package com.beiye.drivertransport.fragment;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.android.frame.adapter.CommonAdapter;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.DataStatisticsActivity;
import com.beiye.drivertransport.SubActivity.EnterpriseAuditActivity;
import com.beiye.drivertransport.SubActivity.IllegalLearningActivity;
import com.beiye.drivertransport.SubActivity.OnlineEducationActivity;
import com.beiye.drivertransport.SubActivity.SubBusinessManagemenSafeLearnActivity;
import com.beiye.drivertransport.SubActivity.SubCompanyLearnActivity;
import com.beiye.drivertransport.SubActivity.SubLearnRecordActivity;
import com.beiye.drivertransport.accident.training.AccidentTrainingActivity;
import com.beiye.drivertransport.adapter.MaintSecondAdapter;
import com.beiye.drivertransport.adapter.PopWindowApt;
import com.beiye.drivertransport.adapter.PopWindowRoleApt;
import com.beiye.drivertransport.adapter.StrationCityApt;
import com.beiye.drivertransport.adapter.SubCarApt;
import com.beiye.drivertransport.bean.AppModule;
import com.beiye.drivertransport.bean.CarBean;
import com.beiye.drivertransport.bean.CheckBean;
import com.beiye.drivertransport.bean.ContactBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.MineUseBean;
import com.beiye.drivertransport.bean.OrgIdBean;
import com.beiye.drivertransport.bean.RoleNameBean;
import com.beiye.drivertransport.bean.SpecifiedLearnAllBean;
import com.beiye.drivertransport.bean.StrationCityBean;
import com.beiye.drivertransport.bean.TrainingIndvPriceCheckBean;
import com.beiye.drivertransport.bean.UpPhotoBean;
import com.beiye.drivertransport.bean.UserBean;
import com.beiye.drivertransport.bean.UserVipCheckBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.header.WindmillHeader;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.prejobtraining.SubPreJobTrainingActivity;
import com.beiye.drivertransport.safelearn.SpecifiedLearningHomeActivity;
import com.beiye.drivertransport.thematic.learning.AlltopicsActivity;
import com.beiye.drivertransport.thematic.learning.NewPaymentActivity;
import com.beiye.drivertransport.thematic.learning.ThematicLearnRecordActivity;
import com.beiye.drivertransport.thematic.learning.ThematiclearningActivity;
import com.beiye.drivertransport.utils.CameraCanUseUtils;
import com.beiye.drivertransport.utils.Constants;
import com.beiye.drivertransport.utils.FileUtil;
import com.beiye.drivertransport.utils.HelpUtil;
import com.beiye.drivertransport.utils.ImageUtil;
import com.beiye.drivertransport.utils.LogUtils;
import com.beiye.drivertransport.utils.MessageEvent;
import com.beiye.drivertransport.utils.SharePerferenceUtils;
import com.beiye.drivertransport.utils.TakePhotoDialog;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.ToastUtil;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.beiye.drivertransport.view.ShowGridView;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.squareup.picasso.Picasso;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

//首页
public class HomeFgt extends TwoBaseFgt {

    ScrollView scrollView;

    PtrClassicFrameLayout ptr_main;//下拉刷新

    TextView tvcompany;

    TextView img_home12;

            TextView fgt_management;

    LinearLayout le_parent_learn;//安全学习模块

    LinearLayout le_parent_check;//安全管理模块

    ShowGridView learn_gv;//安全教育网格展示

    ShowGridView maintenance_gv;//安全管理网格展示

    TextView tv_role;//角色

    RelativeLayout re_role;//角色弹窗

    RelativeLayout re_recruit;//招聘

    ImageView img_role;//角色箭头

    TextView tv_name;

    TextView tv_homelearn2;//敬请期待

    RelativeLayout re_specifiedlearn;//专题学习布局

    ImageView tv_all;//专题全部

    ShowGridView specified_gv;//专题

    TextView tv_homelearn1;

    private int stIdFlag;//专题标识（0：青海、四川，1：甘肃）

    public static final int mNotificationId = 001;

    //下拉次数
    private int ptrTimes;
    private PopupWindow mPopWindow;
    private PopWindowApt popWindowApt;
    ArrayList<LoginUserBean.DataBean.CurUserOrgBean> cusList = new ArrayList<>();
    ArrayList<LoginUserBean.DataBean.CurUserOrgBean> useList = new ArrayList<>();
    ArrayList<LoginUserBean.DataBean.CurUserOrgBean> cusList1 = new ArrayList<>();
    ArrayList<SpecifiedLearnAllBean.RowsBean> speciledList = new ArrayList<>();
    ArrayList<SpecifiedLearnAllBean.RowsBean> cashList = new ArrayList<>();
    ArrayList<CarBean.RowsBean> carList = new ArrayList<>();

    //请求访问外部存储
    private static final int READ_EXTERNAL_STORAGE_REQUEST_CODE = 103;
    //请求写入外部存储
    private static final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 104;
    private File tempFile;
    //请求相机
    private static final int REQUEST_CAPTURE = 100;
    //请求相册
    private static final int REQUEST_PICK = 101;
    //请求截图
    private static final int REQUEST_CROP_PHOTO = 102;
    private int type;
    private ArrayList<AppModule.RowsBean> moduleTypeOneList = new ArrayList<>();
    private ArrayList<AppModule.RowsBean> moduleTypeTwoList = new ArrayList<>();
    private SubCarApt subCarApt;
    private PopupWindow mPlatoPopWindow;
    private PopupWindow mPlatomaintencePopWindow;
    private MaintAdapter maintAdapter;
    private MaintSecondAdapter maintAdapter1;
    ArrayList<RoleNameBean> roleList = new ArrayList<>();
    private PopWindowRoleApt popWindowRoleApt;
    private PopupWindow mPopWindowRole;
    private SpecifiedLearnGVAdapter specifiedLearnGVAdapter;
    ArrayList<AppModule.RowsBean> speList = new ArrayList<>();
    ArrayList<OrgIdBean.RowsBean> orgidlist = new ArrayList<>();
    private String idcNo;
    private String nation;
    private String address;
    private String userName;
    private String userId;
    private Bundle certListBundle;

    ArrayList<StrationCityBean.DataBean.NextListBean> nextDataList1 = new ArrayList<>();
    private PopupWindow mStratisCityPopWindow;
    private StrationCityApt strationCityApt1;
    private String nextAdId1;

    private String[] citys;

    private boolean checkResult; //是否已经购买会员
    private boolean behalfCharge; //是否开启了代收费

    private static final int CHECK_IS_BUY_MEMBER = 15;
    private static final int CHECK_BEHALF_CHARGE = 17;
    private int ccMark;
    private int feeType;
    private String adId;
    private int uoSn;

    private String contactPhone = "023-86058530";
    private int reapplyMark;//重新申请标记

    @Override
    public int getLayoutId() {
        return R.layout.main_home_fgt;
    }

    @Override
    public void onClick(View view) {

    }


    private void showRolePopupWindow() {
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.popwindowrole_layout, null);
        mPopWindowRole = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        ListView lv_role = (ListView) contentView.findViewById(R.id.lv_role);
        lv_role.setAdapter(popWindowRoleApt);
        mPopWindowRole.showAtLocation(tvcompany, Gravity.CENTER, 0, 0);
        lv_role.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                if (popWindowRoleApt != null) {
                    String Name = popWindowRoleApt.getItem(position).getName();
                    tv_role.setText(Name);
                    fgt_management.setText("安全管理");
                    mPopWindowRole.dismiss();
                    SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                    String adId = sp.getString("adId", "");
                    String orgId = sp.getString("orgId", "");
                    int userMark = sp.getInt("userMark", 0);
                    if (Name.equals("我是企业管理人员")) {
                        SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp1.edit();
                        edit.putString("name" + orgId, Name);
                        edit.commit();
                        if (userMark == 2) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, Name);
                        } else if (userMark == 3) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, Name);
                        }
                    } else if (Name.equals("我是从业人员")) {
                        fgt_management.setText("安全作业");
                        SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp1.edit();
                        edit.putString("name" + orgId, Name);
                        edit.commit();
                        if (userMark == 2) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 1);
                            edit.commit();
                            appModule(adId, 2, 1, Name);
                        } else if (userMark == 3) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 1);
                            edit.commit();
                            appModule(adId, 2, 1, Name);
                        } else if (userMark == 0) {
                            edit.putInt("userMark", 0);
                            edit.putInt("eeMark", 1);
                            edit.commit();
                            appModule(adId, 0, 1, Name);
                        }
                    } else if (Name.equals("我是企业负责人")) {
                        SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp1.edit();
                        edit.putString("name" + orgId, Name);
                        edit.commit();
                        if (userMark == 2) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, Name);
                        } else if (userMark == 3) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, Name);
                        }
                    } else if (Name.equals("我是车主")) {
                        SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp1.edit();
                        edit.putString("name" + orgId, Name);
                        edit.commit();
                        if (userMark == 2) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 3);
                            edit.commit();
                            appModule(adId, 2, 3, Name);
                        } else if (userMark == 3) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 3);
                            edit.commit();
                            appModule(adId, 2, 3, Name);
                        } else if (userMark == 0) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 3);
                            edit.commit();
                            appModule(adId, 2, 3, Name);
                        }
                    }
                }
            }
        });

    }

    private void plateNumbermaintenance(final String orgId, final String orgName) {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        //查询车牌号
        OkGo.get(AppInterfaceConfig.BASE_URL + "vehicle/vehicleOrg/getVehicles/" + userId)
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String result, Call call, Response response) {

                        CarBean carBean = JSON.parseObject(result, CarBean.class);
                        List<CarBean.RowsBean> rows = carBean.getRows();
                        if (rows.size() == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您未在企业“" + orgName + "”绑定车辆,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        carList.clear();
                        for (int i = 0; i < rows.size(); i++) {
                            if (rows.get(i).getOrgId().equals(orgId)) {
                                carList.add(rows.get(i));
                            }
                        }
                        if (carList.size() == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您未在企业“" + orgName + "”绑定车辆,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;

                        } else {
                            subCarApt = new SubCarApt(getActivity(), carList, R.layout.car_item_layout);
                            if (subCarApt == null || subCarApt.getCount() == 0) {
                                HelpUtil.showTiShiDialog(getContext(), "您未在企业“" + orgName + "”绑定车辆,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                                return;
                            } else {
                                if (subCarApt.getCount() == 1) {

                                } else {

                                    showPlatomaintenecePopwindow();
                                }
                            }

                        }

                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);

                    }
                });
    }

    private void showPlatomaintenecePopwindow() {
        //设置contentView
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.two_popwindow, null);
        mPlatomaintencePopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        ListView lv_car = (ListView) contentView.findViewById(R.id.lv_car1);
        lv_car.setAdapter(subCarApt);
        mPlatomaintencePopWindow.showAtLocation(tvcompany, Gravity.CENTER, 0, 0);
        TextView tv_ture = (TextView) contentView.findViewById(R.id.tv_two_sure);
        tv_ture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sp = getContext().getSharedPreferences("MessageEvent11",
                        Context.MODE_PRIVATE);
                String vid = sp.getString("vid", "");
                if (vid.equals("")) {
                    Toast.makeText(getContext(), "请选择车辆", Toast.LENGTH_LONG).show();
                    return;
                }
                               SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();
                mPlatomaintencePopWindow.dismiss();
            }
        });
    }

    private void plateNumber(final String orgId, final String orgName) {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        //查询车牌号
        OkGo.get(AppInterfaceConfig.BASE_URL + "vehicle/vehicleOrg/getVehicles/" + userId)
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String result, Call call, Response response) {

                        CarBean carBean = JSON.parseObject(result, CarBean.class);
                        List<CarBean.RowsBean> rows = carBean.getRows();
                        if (rows.size() == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您未在企业“" + orgName + "”绑定车辆,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        carList.clear();
                        for (int i = 0; i < rows.size(); i++) {
                            if (rows.get(i).getOrgId().equals(orgId)) {
                                carList.add(rows.get(i));
                            }
                        }
                        if (carList.size() == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您未在企业“" + orgName + "”绑定车辆,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;

                        } else {
                            subCarApt = new SubCarApt(getActivity(), carList, R.layout.car_item_layout);
                            if (subCarApt == null || subCarApt.getCount() == 0) {
                                HelpUtil.showTiShiDialog(getContext(), "您未在企业“" + orgName + "”绑定车辆,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                                return;
                            } else {

                            }

                        }

                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);

                    }
                });


    }

    private void showPlatoPopwindow() {
        //设置contentView
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.two_popwindow, null);
        mPlatoPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        ListView lv_car = (ListView) contentView.findViewById(R.id.lv_car1);
        lv_car.setAdapter(subCarApt);
        mPlatoPopWindow.showAtLocation(tvcompany, Gravity.CENTER, 0, 0);
        TextView tv_ture = (TextView) contentView.findViewById(R.id.tv_two_sure);
        tv_ture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sp = getContext().getSharedPreferences("MessageEvent11",
                        Context.MODE_PRIVATE);
                String vid = sp.getString("vid", "");

                if (vid.equals("")) {
                    Toast.makeText(getContext(), "请选择车辆", Toast.LENGTH_LONG).show();
                    return;
                }
                SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();
                mPlatoPopWindow.dismiss();
            }
        });
    }


    @Override
    public void onUserVisible() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);//反注册EventBus
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(MessageEvent event) {
        if (event.getType() == MessageEvent.TYPE_12) {
            SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
            String stName = sp.getString("stName", "");
            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getContext());
            builder1.setMessage("您已成功购买 " + "[专题学习]" + stName + "。");
            builder1.setTitle("提示:");
            builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                    String orgId = sp.getString("orgId", "");
                    String orgName = sp.getString("orgName", "");
                    int stId = sp.getInt("stId", 0);
                    int ihveMark = sp.getInt("ihveMark", 0);
                    int tmenuMark = sp.getInt("tmenuMark", 0);
                    int qmenuMark = sp.getInt("qmenuMark", 0);
                    int peMenuMark = sp.getInt("peMenuMark", 0);
                    int emenuMark = sp.getInt("emenuMark", 0);
                    int position = sp.getInt("position", 0);
                    String adId = sp.getString("adId", "");
                    String rolename = sp.getString("rolename", "");
                    String iconUrl = sp.getString("iconUrl", "");
                    int seqTMark = sp.getInt("seqTMark", 0);

                    Bundle bundle = new Bundle();
                    bundle.putString("orgId", orgId);
                    bundle.putInt("stId", stId);
                    bundle.putInt("position", position);
                    bundle.putString("orgName", orgName);
                    bundle.putString("adId", adId);
                    bundle.putString("rolename", rolename);
                    bundle.putString("iconUrl", iconUrl);
                    bundle.putInt("ihveMark", ihveMark);
                    bundle.putInt("tmenuMark", tmenuMark);
                    bundle.putInt("qmenuMark", qmenuMark);
                    bundle.putInt("peMenuMark", peMenuMark);
                    bundle.putInt("emenuMark", emenuMark);
                    bundle.putInt("seqTMark", seqTMark);
                    bundle.putInt("reapplyMark",reapplyMark);
                    startActivity(ThematiclearningActivity.class, bundle);
                }
            });
            builder1.create().show();
        } else if (event.getType() == MessageEvent.TYPE_1) {
            HelpUtil.showTiShiDialog(getContext(), "您购买失败");
        }
    }

    @Override
    public void initData() {
        scrollView = (ScrollView) getActivity().findViewById(R.id.scroll_view);
        ptr_main = (PtrClassicFrameLayout)getActivity().findViewById(R.id.ptr_main);
        tvcompany = (TextView) getActivity().findViewById(R.id.tv_company);
        img_home12 = (TextView) getActivity().findViewById(R.id.img_home12);
        fgt_management = (TextView) getActivity().findViewById(R.id.fgt_management);
        le_parent_learn = (LinearLayout)getActivity().findViewById(R.id.le_parent_learn);
        le_parent_check = (LinearLayout)getActivity().findViewById(R.id.le_parent_check);
        learn_gv = (ShowGridView)getActivity().findViewById(R.id.learn_gv);
        maintenance_gv = (ShowGridView)getActivity().findViewById(R.id.maintenance_gv);
        tv_role = (TextView)getActivity().findViewById(R.id.tv_role);
        re_role = (RelativeLayout)getActivity().findViewById(R.id.re_role);
        re_recruit = (RelativeLayout)getActivity().findViewById(R.id.re_recruit);
        img_role = (ImageView)getActivity().findViewById(R.id.img_role);
        tv_name = (TextView) getActivity().findViewById(R.id.tv_name);
        tv_homelearn2 = (TextView)getActivity().findViewById(R.id.tv_homelearn2);
        re_specifiedlearn = (RelativeLayout)getActivity().findViewById(R.id.re_specifiedlearn);
        tv_all = (ImageView)getActivity().findViewById(R.id.tv_all);
        specified_gv = (ShowGridView)getActivity().findViewById(R.id.specified_gv);
        tv_homelearn1 = (TextView) getActivity().findViewById(R.id.tv_homelearn1);

        tv_homelearn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences thematicRecordSp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                Bundle bundle1=new Bundle();
                bundle1.putString("rolename",thematicRecordSp.getString("rolename", ""));
                bundle1.putString("adId",thematicRecordSp.getString("adId", ""));
                startActivity(ThematicLearnRecordActivity.class, bundle1);
            }
        });

        tv_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Utils.isFastClicker()) {
                    return;
                }

                if (isYCJT(adId)) { //判断是否为永川
                    return;
                }
                SharedPreferences sp1 = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                String adId = sp1.getString("adId", "");
                String orgId1 = sp1.getString("orgId", "");
                String rolename = sp1.getString("rolename", "");
                String orgName1 = sp1.getString("orgName", "");
                int orgMark1 = sp1.getInt("orgMark", 0);
                int ihveMark = sp1.getInt("ihveMark", 0);
                String photoUrl = sp1.getString("personphotoUrl", "");
                Bundle bundle2 = new Bundle();
                bundle2.putString("adId", adId);
                bundle2.putString("orgId", orgId1);
                bundle2.putString("rolename", rolename);
                bundle2.putString("orgName", orgName1);
                bundle2.putInt("orgMark", orgMark1);
                bundle2.putInt("ihveMark", ihveMark);
                bundle2.putString("photoUrl", photoUrl);
                startActivity(AlltopicsActivity.class, bundle2);
            }
        });

        tvcompany.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (popWindowApt == null) {
                    return;
                }
                if (popWindowApt.getCount() == 1) {
                    return;
                } else {
                    showPopupWindow();
                }
            }
        });

        tv_role.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (popWindowRoleApt == null) {
                    return;
                }
                if (popWindowRoleApt.getCount() == 1) {

                    return;
                } else {
                    showRolePopupWindow();
                }
            }
        });


        //注册EventBus
        EventBus.getDefault().register(this);
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userName = data.getUserName();
        if (userName != null) {
            tv_name.setText("您好，" + userName);
        }
        //下拉刷新
        final WindmillHeader header = new WindmillHeader(getActivity());
        final ImageLoadingListener listener = new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String imageUri, View view) {

            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                ptr_main.refreshComplete();
            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                ptr_main.refreshComplete();
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {
                ptr_main.refreshComplete();
            }
        };


        ptr_main.setHeaderView(header);
        ptr_main.addPtrUIHandler(header);
        //下拉刷新
        ptr_main.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ptruseData();//刷新从新获取当前用户机构信息
                        usefacephoto(); //人脸识别要求上传头像和签名
                        ptrTimes++;
                        ptr_main.refreshComplete();
                    }
                }, 2000);
            }
        });

        //专题培训点击事件
        specified_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (Utils.isFastClicker()) {
                    return;
                }
                int stId = specifiedLearnGVAdapter.getItem(position).getStId();
                int disableMark = specifiedLearnGVAdapter.getItem(position).getDisableMark();
                String disableDesc = specifiedLearnGVAdapter.getItem(position).getDisableDesc();
                String stName = specifiedLearnGVAdapter.getItem(position).getStName();
                float price = specifiedLearnGVAdapter.getItem(position).getPrice();
                Integer uschSn = specifiedLearnGVAdapter.getItem(position).getUschSn();
                String iconUrl2 = specifiedLearnGVAdapter.getItem(position).getIconUrl2();
                Integer chargeMark = specifiedLearnGVAdapter.getItem(position).getChargeMark();
                Integer payMark = specifiedLearnGVAdapter.getItem(position).getPayMark();
                Integer tmenuMark = specifiedLearnGVAdapter.getItem(position).getTmenuMark();
                Integer qmenuMark = specifiedLearnGVAdapter.getItem(position).getQmenuMark();
                Integer peMenuMark = specifiedLearnGVAdapter.getItem(position).getPeMenuMark();
                Integer emenuMark = specifiedLearnGVAdapter.getItem(position).getEmenuMark();
                reapplyMark=specifiedLearnGVAdapter.getItem(position).getReapplyMark();

                Integer thematicFaceRecgMark = specifiedLearnGVAdapter.getItem(position).getFaceRecgMark();
                SharePerferenceUtils.putInt(getContext(), "thematicFaceRecgMark", thematicFaceRecgMark);

                int seqTMark = specifiedLearnGVAdapter.getItem(position).getSeqTMark();
                SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                String orgName = sp.getString("orgName", "");
                String adId = sp.getString("adId", "");
                int orgMark = sp.getInt("orgMark", 0);
                int ihveMark = sp.getInt("ihveMark", 0);
                String orgId = sp.getString("orgId", "");
                String rolename = sp.getString("rolename", "");
                String photoUrl = sp.getString("personphotoUrl", "");

                if (isYCJT(adId)) { //判断永川交通
                    return;
                }

                if (disableMark == 1)//禁用提示框
                {
                    String decstr = Utils.removeHtmlTag(disableDesc);
                    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                    View view1 = View.inflate(getContext(), R.layout.diolog_learn_layout, null);
                    TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
                    TextView tv_title = (TextView) view1.findViewById(R.id.title);//输入头部
                    tv_title.setVisibility(View.VISIBLE);
                    tv_title.setText("温馨提示");
                    tv_message.setText(decstr);
                    TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
                    btn_sure.setText("取消");
                    btn_cancel.setVisibility(View.GONE);
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view1);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(true);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();

                        }
                    });

                    return;
                }

                /*boolean orgStatus = orgStatus(orgMark, orgName);
                if (!orgStatus) {
                    return;
                }*/
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("stName", stName);
                edit.putString("iconUrl", iconUrl2);
                edit.putInt("position", position);
                edit.putInt("stId", stId);
                edit.putInt("tmenuMark", tmenuMark);
                edit.putInt("qmenuMark", qmenuMark);
                edit.putInt("peMenuMark", peMenuMark);
                edit.putInt("emenuMark", emenuMark);
                edit.putInt("seqTMark", seqTMark);
                edit.commit();

                Bundle bundle = new Bundle();
                bundle.putString("userName", userName);
                bundle.putString("orgId", orgId);
                bundle.putInt("stId", stId);
                bundle.putString("orgName", orgName);
                bundle.putString("adId", adId);
                bundle.putString("rolename", rolename);
                bundle.putString("iconUrl", iconUrl2);
                bundle.putInt("position", position);
                bundle.putInt("ihveMark", ihveMark);
                bundle.putInt("tmenuMark", tmenuMark);
                bundle.putInt("qmenuMark", qmenuMark);
                bundle.putInt("peMenuMark", peMenuMark);
                bundle.putInt("emenuMark", emenuMark);
                bundle.putInt("seqTMark", seqTMark);
                bundle.putInt("chargeMark", chargeMark);
                bundle.putInt("paytag", 1);
                bundle.putFloat("price", price);
                bundle.putString("stName", stName);
                bundle.putInt("reapplyMark",reapplyMark);
                bundle.putString("uqcSn", null);


                if (uschSn == null) { //没有学时序列号

                    if (stId == 630011 || stId == 630012) { //青海继续教育
                        stIdFlag=0;
                        bundle.putString("province", "青海");
                        certListBundle = bundle;

                        if (idcNo == null || idcNo.length() == 0) {
                            showIdcNoDialog();
                        } else {
                        }
                        return;
                    }
                    if (stId == 510016 || stId == 510017 || stId == 510018 || stId == 510019) { //四川继续教育专题培训
                        stIdFlag=0;
                        if (photoUrl.equals("")) {
                            showTakePhotoPopupWindow();
                            return;
                        }
                        bundle.putString("province", "四川");
                        certListBundle = bundle;
                        if (idcNo == null || idcNo.length() == 0 || nation == null || nation.length() == 0 || address == null || address.length() == 0) {
                            showUserMsgDialog();
                        } else {

                        }
                        return;
                    }

                    if(stId==730002 || stId==730003 || stId==730004 || stId==320101){//甘肃继续教育
                        stIdFlag=1;
                        certListBundle = bundle;

                        if (idcNo == null || idcNo.length() == 0) {
                            showIdcNoDialog();
                            return;
                        }
                    }

                    if (chargeMark == 1)//免费
                    {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        LoginUserBean.DataBean data = userInfo.getData();
                        String userId = data.getUserId();
                        String phoneSign = getPhoneSign();//设备的唯一标识
                        initPayMent(userId, orgId, 0, phoneSign, stId);
                    } else if (chargeMark == 3)//考试前付费
                    {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        LoginUserBean.DataBean data = userInfo.getData();
                        String userId = data.getUserId();
                        String phoneSign = getPhoneSign();//设备的唯一标识
                        initPayMent(userId, orgId, 0, phoneSign, stId);
                    } else if (chargeMark == 2)//进入前付费
                    {
                        startActivity(NewPaymentActivity.class, bundle);
                    }
                } else {//uschSn有值有学时序列号

                    if (chargeMark == 1)//免费
                    {
                        startActivity(ThematiclearningActivity.class, bundle);
                    } else if (chargeMark == 3)//考试前付费
                    {
                        startActivity(ThematiclearningActivity.class, bundle);
                    } else if (chargeMark == 2)//进入前付费
                    {
                        if (payMark == 2)//已付费
                        {
                            startActivity(ThematiclearningActivity.class, bundle);
                        } else if (payMark == 0) {//待支付630011

                            if (stId == 630011 || stId == 630012) { //青海继续教育
                                stIdFlag=0;
                                bundle.putString("province", "青海");
                                certListBundle = bundle;
                            }
                            if (stId == 510016 || stId == 510017 || stId == 510018 || stId == 510019) { //四川继续教育专题培训
                                stIdFlag=0;
                                if (photoUrl.equals("")) {
                                    showTakePhotoPopupWindow();
                                    return;
                                }

                                bundle.putString("province", "四川");
                                certListBundle = bundle;
                                return;
                            }
                            if(stId==730002 || stId==730003 || stId==730004 || stId==320101){//甘肃继续教育
                                stIdFlag=1;
                                certListBundle = bundle;

                                if (idcNo == null || idcNo.length() == 0) {
                                    showIdcNoDialog();
                                    return;
                                }
                            }

                            startActivity(NewPaymentActivity.class, bundle);
                        } else if (payMark == 1)//免费
                        {
                            startActivity(ThematiclearningActivity.class, bundle);
                        }
                    }
                }
            }
        });

        //安全学习点击事件
        learn_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                int orgMark = sp.getInt("orgMark", 0);

                int minPer = sp.getInt("minPer", 0);
                int readInterval = sp.getInt("readInterval", 0);
                int signMark = sp.getInt("signMark", 0);
                int Mark = sp.getInt("Mark", 0);
                int eeMark = sp.getInt("eeMark", 1);
                String orgId = sp.getString("orgId", "");
                String forbidHour = sp.getString("forbidHour", "");
                int photoMark = sp.getInt("photoMark", 0);
                int mtPhotoNo = sp.getInt("mtPhotoNo", 0);
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                int feeType = sp.getInt("feeType", 0);
                String photoUrl = sp.getString("personphotoUrl", "");
                String orgName = sp.getString("orgName", "");
                int mtSeqMark = sp.getInt("mtSeqMark", 0);
                int allowMuT = sp.getInt("allowMuT", 0);
                int pjtMinPer = sp.getInt("pjtMinPer", 0);
                int ftId = sp.getInt("ftId", 0);
                String adId = sp.getString("adId", "");
                String channelId = sp.getString("channelId", "");
                int mtPeriodMark = sp.getInt("mtPeriodMark", 0);
                int chNoMark = sp.getInt("chNoMark", 0);

                if (Utils.isFastClicker()) { //快速点击判断
                    return;
                }

                if (isYCJT(adId)) { //判断是否为永川交通
                    return;
                }


                boolean orgStatus = orgStatus(orgMark, orgName); //企业状态判断
                if (!orgStatus) {
                    return;
                }

                int moduleId = maintAdapter.getItem(position).getModuleId();
                if(moduleId!=20100003 && moduleId!=20100009){ //排查岗前培训和违章培训
                    if (buyMemberCheck()) { //是否有包年会员判断
                        return;
                    }
                }


                Bundle bundle = new Bundle();
                bundle.putInt("minPer", minPer);
                bundle.putInt("readInterval", readInterval);
                bundle.putInt("signMark", signMark);
                bundle.putInt("Mark", Mark);
                bundle.putString("orgId", orgId);
                bundle.putString("forbidHour", forbidHour);
                bundle.putInt("photoMark", photoMark);
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putInt("feeType", feeType);
                bundle.putString("personphotoUrl", photoUrl);
                bundle.putString("orgName", orgName);
                bundle.putInt("mtSeqMark", mtSeqMark);
                bundle.putInt("allowMuT", allowMuT);
                bundle.putInt("pjtMinPer", pjtMinPer);
                bundle.putInt("ftId", ftId);
                bundle.putString("adId", adId);
                bundle.putString("channelId", channelId);
                bundle.putString("jumpType", "homeFgt");

                SharedPreferences sharedPreferences = getActivity().getSharedPreferences("StaticData", Context.MODE_PRIVATE);
                SharedPreferences.Editor spEditor = sharedPreferences.edit();
                spEditor.putString("adId", adId);
                spEditor.putInt("uoSn", uoSn);
                spEditor.putString("orgId", orgId);
                spEditor.putInt("faceRecgMark", faceRecgMark);
                spEditor.putString("personphotoUrl", photoUrl);
                spEditor.putInt("mtPhotoNo", mtPhotoNo);
                spEditor.putString("orgName", orgName);
                spEditor.commit();

                switch (moduleId) {

                    case 20100001://从业人员日常培训
                        if (eeMark != 1) {
                            HelpUtil.showTiShiDialog(getContext(), "此功能仅供从业人员使用");
                            return;
                        }

                        if (Mark == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您已被企业管理员禁用,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 2) {
                            HelpUtil.showTiShiDialog(getContext(), "无企业,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 4) {
                            HelpUtil.showTiShiDialog(getContext(), "您暂不能参加安全培训，若有疑问请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 3) {
                            if (feeType == 1) {//企业付费
                                HelpUtil.showTiShiDialog(getContext(), "您需要企业审核后才能继续使用，请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                                return;
                            }
                            if (faceRecgMark == 1 || faceRecgMark == 2) {
                                if (photoUrl.equals("")) {
                                    showTakePhotoPopupWindow();
                                    return;
                                }
                            }
                        } else if (Mark == 1) {
                            if (speciledList.size() == 0) {//无专项培训不判断
                                if (feeType == 1) {//企业支付
                                    if (mtPeriodMark == 0 && chNoMark == 0) {
                                        HelpUtil.showTiShiDialog(getContext(), "您所在企业学时不足，请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                                        return;
                                    }
                                    if (faceRecgMark == 1 || faceRecgMark == 2) {
                                        if (photoUrl.equals("")) {
                                            showTakePhotoPopupWindow();
                                            return;
                                        }
                                    }
                                    startActivity(SpecifiedLearningHomeActivity.class, bundle);
                                } else if (feeType == 2) {//个人支付
                                    if (faceRecgMark == 1 || faceRecgMark == 2) {
                                        if (photoUrl.equals("")) {
                                            showTakePhotoPopupWindow();
                                            return;
                                        }
                                    }
                                }
                            } else {//有专项培训要判断
                                if (feeType == 1) {//企业支付
                                    if (mtPeriodMark == 0 && chNoMark == 0) {
                                        HelpUtil.showTiShiDialog(getContext(), "您所在企业学时不足，请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                                        return;
                                    }
                                    if (faceRecgMark == 1 || faceRecgMark == 2) {
                                        if (photoUrl.equals("")) {
                                            showTakePhotoPopupWindow();
                                            return;
                                        }
                                    }
                                } else if (feeType == 2) {//个人支付
                                    if (faceRecgMark == 1 || faceRecgMark == 2) {
                                        if (photoUrl.equals("")) {
                                            showTakePhotoPopupWindow();
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        startActivity(SpecifiedLearningHomeActivity.class, bundle);
                        break;
                    case 20100002://学习记录
                        startActivity(SubLearnRecordActivity.class, bundle);
                        break;
                    case 20100003://岗前培训
                        if (eeMark != 1) {
                            HelpUtil.showTiShiDialog(getContext(), "此功能仅供从业人员使用");
                            return;
                        }
                        if (Mark == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您已被企业管理员禁用,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 2) {
                            HelpUtil.showTiShiDialog(getContext(), "无企业,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        if (faceRecgMark == 1 || faceRecgMark == 2) {
                            if (photoUrl.equals("")) {
                                showTakePhotoPopupWindow();
                                return;
                            }
                        }
                        startActivity(SubPreJobTrainingActivity.class, bundle);
                        break;
                    case 20100004://在线测试
                        if (Mark == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您已被企业管理员禁用,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 2) {
                            HelpUtil.showTiShiDialog(getContext(), "无企业,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        if (faceRecgMark == 1 || faceRecgMark == 2) {
                            if (photoUrl.equals("")) {
                                showTakePhotoPopupWindow();
                                return;
                            }
                        }
                        startActivity(OnlineEducationActivity.class, bundle);
                        break;
                    case 20100005://学习统计
                        startActivity(DataStatisticsActivity.class, bundle);
                        break;
                    case 20100006://企业管理员安全学习
                        if (Mark == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您已被企业管理员禁用,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 2) {
                            HelpUtil.showTiShiDialog(getContext(), "无企业,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        startActivity(SubBusinessManagemenSafeLearnActivity.class, bundle);
                        break;
                    case 20100007://单位人员安全学习
                        if (Mark == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您已被企业管理员禁用,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 2) {
                            HelpUtil.showTiShiDialog(getContext(), "无企业,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        startActivity(SubCompanyLearnActivity.class, bundle);
                        //startActivity(SubCompanySafeLearnActivity.class, bundle);
                        break;
                    case 20100008://审核学习
                        startActivity(EnterpriseAuditActivity.class, bundle);
                        break;
                    case 20100009://违章学习
                        if (eeMark != 1) {
                            HelpUtil.showTiShiDialog(getContext(), "此功能仅供从业人员使用");
                            return;
                        }
                        if (Mark == 0) {
                            HelpUtil.showTiShiDialog(getContext(), "您已被企业管理员禁用,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        } else if (Mark == 2) {
                            HelpUtil.showTiShiDialog(getContext(), "无企业,请联系企业管理人员或者平台管理员（" + contactPhone + "）");
                            return;
                        }
                        if (photoUrl.equals("")) {
                            showTakePhotoPopupWindow();
                            return;
                        }
                        startActivity(IllegalLearningActivity.class, bundle);
                        break;
                    case 20100012://事故培训
                        startActivity(AccidentTrainingActivity.class, bundle);
                        break;
                }
            }
        });

        //安全管理点击事件
        maintenance_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                int moduleId = maintAdapter1.getItem(position).getModuleId();
                SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);

                int orgMark = sp.getInt("orgMark", 0);
                String orgId = sp.getString("orgId", "");
                String orgName = sp.getString("orgName", "");
                String adId = sp.getString("adId", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                int ftId = sp.getInt("ftId", 0);
                String photoUrl = sp.getString("personphotoUrl", "");

                String channelId = sp.getString("channelId", "");
                int feeType = sp.getInt("feeType", 0);

                if (Utils.isFastClicker()) { //快速点击判断
                    return;
                }

                if (buyMemberCheck()) {   //判断是否需要购买会员
                    return;
                }

                if (isYCJT(adId)) { //判断是否为永川交通
                    return;
                }

                boolean orgStatus = orgStatus(orgMark, orgName);
                if (!orgStatus) {
                    return;
                }

                Bundle bundle = new Bundle();
                bundle.putString("orgId", orgId);
                bundle.putString("orgName", orgName);
                bundle.putString("adId", adId);
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("personphotoUrl", photoUrl);
                bundle.putString("channelId", channelId);
                bundle.putInt("ftId", ftId);


                switch (moduleId) {
                    case 20200004://二级维护
                        plateNumber(orgId, orgName);//查询车辆
                        break;
                    case 20200005://车辆维修
                        plateNumbermaintenance(orgId, orgName);//查询车辆
                        break;
                }
            }
        });
    }


    private void showUserMsgDialog() {
        //设置contentView
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_moreinput_layout, null);
        mPopWindow = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        mPopWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);

        EditText etIdcNo = (EditText) contentView.findViewById(R.id.dg_moreInput_et_idcNo);//输入内容
        EditText etNation = (EditText) contentView.findViewById(R.id.dg_moreInput_et_nation);//输入内容
        EditText etAddress = (EditText) contentView.findViewById(R.id.dg_moreInput_et_address);//输入内容
        TextView btn_sure = (TextView) contentView.findViewById(R.id.positiveButton);
        TextView btn_false = (TextView) contentView.findViewById(R.id.negativeButton);
        Spinner spCity = (Spinner) contentView.findViewById(R.id.dg_moreInput_rv_city);

        if (!(idcNo == null || idcNo.length() == 0)) {
            etIdcNo.setText(idcNo);
        }

        if (!(nation == null || nation.length() == 0)) {
            etNation.setText(nation);
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, citys);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spCity.setAdapter(adapter);
        spCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                address = citys[i];
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });


        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String idcNoStr = etIdcNo.getText().toString().trim();
                String nationStr = etNation.getText().toString().trim();
                String city = etAddress.getText().toString().trim();


                if (idcNoStr.length() == 0) {
                    showToast("请填写身份证号码");
                    return;
                }
                if (!IsIDcard(idcNoStr)) {
                    showToast("身份证无效");
                    return;
                }

                if (nationStr.length() == 0) {
                    showToast("请填写民族");
                    return;
                }

                if (address.equals("选择市")) {
                    showToast("请选择所在城市");
                    return;
                }

                if (city.length() == 0) {
                    showToast("请填写详细地址");
                    return;
                }

                idcNo = idcNoStr;
                nation = nationStr;
                address = "四川省" + address + city;
                LogUtils.e("测试", "onClick: " + address);
                certListBundle.putString("idcNo", idcNo);
                new Login().userAccountUpdateAddNation(userId, idcNo, nation, address, HomeFgt.this, 2);

                mPopWindow.dismiss();
            }
        });

        btn_false.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPopWindow.dismiss();
            }
        });

    }

    private void showIdcNoDialog() {
        //设置contentView
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_input_layout, null);
        mPopWindow = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        mPopWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);


        EditText tv_message = (EditText) contentView.findViewById(R.id.message);//输入内容
        TextView btn_sure = (TextView) contentView.findViewById(R.id.positiveButton);


        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                idcNo = tv_message.getText().toString().trim();
                if (idcNo.length() == 0) {
                    showToast("请填写身份证号码");
                    return;
                }
                if (!IsIDcard(idcNo)) {
                    showToast("身份证无效");
                    return;
                }
                certListBundle.putString("idcNo", idcNo);
                new Login().getImputUserID(userId, idcNo, HomeFgt.this, 2);
                mPopWindow.dismiss();
            }
        });

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPopWindow.dismiss();
                idcNo = "";
            }
        });
    }


    //免费参加专项学习调购买接口
    private void initPayMent(String userId, String orgId, float price, String phoneSign, int stId) {
        new Login().getPayMentApp(userId, orgId, 2, stId, "APP", price, phoneSign, Constants.APP_ID, null, this, 11);
    }

    private void showTakePhotoPopupWindow() {
        TakePhotoDialog.Builder builder = new TakePhotoDialog.Builder(getContext());
        builder.setTitle("为方便后台管理员审核您的日常培训");
        builder.setMessage("请上传您的个人照片");
        builder.setPositiveButton("从手机中选择照片", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //权限判断
                if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {
                    //申请READ_EXTERNAL_STORAGE权限
                    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                            READ_EXTERNAL_STORAGE_REQUEST_CODE);
                } else {
                    //跳转到相册
                    gotoPhoto();
                }

                dialog.dismiss();

                //设置您的操作事项
            }
        });

        builder.setPositiveButton1("拍摄照片", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //权限判断
                if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {
                    //申请WRITE_EXTERNAL_STORAGE权限
                    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            WRITE_EXTERNAL_STORAGE_REQUEST_CODE);
                } else {
                    //跳转到调用系统相机

                    if (!CameraCanUseUtils.isCameraCanUse()) {
                        ToastUtil.showShortToast(getContext(), "请到手机设置界面里找驾运宝允许开启照相");
                        return;
                    }

                    gotoCamera();
                }
                dialog.dismiss();

                //设置您的操作事项
            }
        });
        builder.setNegativeButton("跳过", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                //设置您的操作事项
            }
        });
        builder.create().show();


    }


    //打开相册
    private void gotoPhoto() {
        Log.d("evan", "*****************打开图库********************");
        //跳转到调用系统图库
        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(Intent.createChooser(intent, "请选择图片"), REQUEST_PICK);
    }
    //打开相机
    private void gotoCamera() {
        Log.d("evan", "*****************打开相机********************");
        //创建拍照存储的图片文件
        tempFile = new File(FileUtil.checkDirPath(Environment.getExternalStorageDirectory().getPath() + "/image/"), System.currentTimeMillis() + ".jpg");

        //跳转到调用系统相机
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            //设置7.0中共享文件，分享路径定义在xml/file_paths.xml
            intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(getContext(), com.beiye.drivertransport.BuildConfig.APPLICATION_ID + ".fileProvider", tempFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
        } else {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
        }
        startActivityForResult(intent, REQUEST_CAPTURE);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        switch (requestCode) {
            case REQUEST_CAPTURE: //调用系统相机返回
                if (resultCode == Activity.RESULT_OK) {
                    Uri uri = Uri.fromFile(tempFile);
                    String cropImagePath = FileUtil.getRealFilePathFromUri(getContext(), uri);
                    File file = new File(cropImagePath);
                    LoginUserBean userInfo = UserManger.getUserInfo();
                    LoginUserBean.DataBean data = userInfo.getData();
                    String userId = data.getUserId();
                    try {
                        FileInputStream fis = new FileInputStream(file);
                        Bitmap bitmapByUrl = BitmapFactory.decodeStream(fis);
                        bitmapByUrl = ImageUtil.compressScale(bitmapByUrl);
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
                        bitmapByUrl.compress(Bitmap.CompressFormat.JPEG, 100, bos);
                        bos.flush();
                        bos.close();
                        uploadImg(file, userId);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {

                    }
                }
                break;
            case REQUEST_PICK:  //调用系统相册返回
                if (resultCode == Activity.RESULT_OK) {
                    Uri uri = intent.getData();
                    String cropImagePath = FileUtil.getRealFilePathFromUri(getContext(), uri);
                    File file = new File(cropImagePath);
                    LoginUserBean userInfo = UserManger.getUserInfo();
                    LoginUserBean.DataBean data = userInfo.getData();
                    String userId = data.getUserId();
                    try {
                        FileInputStream fis = new FileInputStream(file);
                        Bitmap bitmapByUrl = BitmapFactory.decodeStream(fis);
                        bitmapByUrl = ImageUtil.compressScale(bitmapByUrl);
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
                        bitmapByUrl.compress(Bitmap.CompressFormat.JPEG, 100, bos);
                        bos.flush();
                        bos.close();
                        uploadImg(file, userId);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {

                    }
                }
                break;
        }
    }

    private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
    private final OkHttpClient client = new OkHttpClient();

    private void uploadImg(File mediaFile, String userId) {
        // mImgUrls为存放图片的url集合
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);

        if (mediaFile != null) {
            builder.addFormDataPart("headPhoto", mediaFile.getName(), RequestBody.create(MEDIA_TYPE_PNG, mediaFile));
            builder.addFormDataPart("userId", userId);
        }
        MultipartBody requestBody = builder.build();
        //构建请求
        Request request = new Request.Builder()
                .url(AppInterfaceConfig.BASE_URL + "wx/uploadOfHeadPhoto")//地址
                .post(requestBody)//添加请求体
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                LogUtils.e("上传失败", e.getLocalizedMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                LogUtils.e("上传成功", str);
                UpPhotoBean upPhotoBean = JSON.parseObject(str, UpPhotoBean.class);
                String data = upPhotoBean.getData();
                Looper.prepare();
                usefacephoto(); //人脸识别要求上传头像和签名
                Looper.loop();
                LogUtils.e("上传图片", data);

            }
        });

    }

    //权限请求结果
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                gotoCamera();
            }
        } else if (requestCode == READ_EXTERNAL_STORAGE_REQUEST_CODE) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                gotoPhoto();
            }
        }
    }


    private void initCompany(LoginUserBean userInfo) {

        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        List<LoginUserBean.DataBean.CurUserOrgBean> curuserOrglist = data.getCur_userOrg();
        cusList.clear();
        if (curuserOrglist.size() == 0) {
            img_home12.setVisibility(View.INVISIBLE);
            learn_gv.setAdapter(null);
            maintenance_gv.setAdapter(null);
            return;
        }
        for (int i = 0; i < curuserOrglist.size(); i++) {
            if (curuserOrglist.get(i).getMark() == 1 || curuserOrglist.get(i).getMark() == 3 || curuserOrglist.get(i).getMark() == 4) {
                cusList.add(curuserOrglist.get(i));
            }
        }
        if (cusList.size() == 0) {
            img_home12.setVisibility(View.INVISIBLE);
            SharedPreferences sppp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor2 = sppp.edit();
            editor2.putInt("Mark", 2);
            editor2.putString("orgId", "");
            editor2.commit();
            tvcompany.setText("");
            return;
        }

        String orgName = cusList.get(0).getOrgName();
        String orgId = cusList.get(0).getOrgId();
        int eeMark = cusList.get(0).getEeMark();
        int mark = cusList.get(0).getMark();
        int userMark = cusList.get(0).getUserMark();
        adId = cusList.get(0).getAdId();
        uoSn = cusList.get(0).getUoSn();
        int orgMark = cusList.get(0).getOrgMark();
        int minPer = cusList.get(0).getMinPer();
        int signMark = cusList.get(0).gettSignMark();
        int photoMark = cusList.get(0).gettPhotoMark();
        int mtPhotoNo = cusList.get(0).getMtPhotoNo();
        int readInterval = cusList.get(0).getReadInterval();
        int pjtMinPer = cusList.get(0).getPjtMinPer();
        String forbidHour = cusList.get(0).getForbidHour();
        int headMark = cusList.get(0).getHeadMark();
        int faceRecgMark = cusList.get(0).getFaceRecgMark();
        String channelId = cusList.get(0).getChannelId();
        int ihveMark = cusList.get(0).getIhveMark();
        int voMark = cusList.get(0).getVoMark();
        int mtPeriodMark = cusList.get(0).getMtPeriodMark();
        int chNoMark = cusList.get(0).getChNoMark();
        int mtSeqMark = cusList.get(0).getMtSeqMark();
        int allowMuT = cusList.get(0).getAllowMuT();
        int ftId = cusList.get(0).getFtId();
        feeType = cusList.get(0).getFeeType();
        ccMark = cusList.get(0).getCcMark();

        SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("Mark", mark);
        editor.putInt("eeMark", eeMark);
        editor.putString("orgId", orgId);
        editor.putString("orgName", orgName);
        editor.putInt("minPer", minPer);
        editor.putInt("pjtMinPer", pjtMinPer);
        editor.putInt("readInterval", readInterval);
        editor.putString("adId", adId);
        editor.putInt("mtPhotoNo", mtPhotoNo);
        editor.putString("forbidHour", forbidHour);
        editor.putInt("userMark", userMark);
        editor.putInt("orgMark", orgMark);
        editor.putInt("signMark", signMark);
        editor.putInt("photoMark", photoMark);
        editor.putInt("orgIdlist", 0);
        editor.putInt("headMark", headMark);
        editor.putInt("faceRecgMark", faceRecgMark);
        editor.putInt("ihveMark", ihveMark);
        editor.putInt("feeType", feeType);
        editor.putInt("voMark", voMark);
        editor.putInt("mtPeriodMark", mtPeriodMark);
        editor.putInt("chNoMark", chNoMark);
        editor.putInt("mtSeqMark", mtSeqMark);
        editor.putInt("allowMuT", allowMuT);
        editor.putString("channelId", channelId);
        editor.putInt("ftId", ftId);
        editor.commit();

        getConnectPhone(orgId);

        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("StaticData", Context.MODE_PRIVATE);
        SharedPreferences.Editor spEditor = sharedPreferences.edit();
        spEditor.putString("adId", adId);
        spEditor.putInt("uoSn", uoSn);
        spEditor.putString("orgId", orgId);
        spEditor.putInt("faceRecgMark", faceRecgMark);
        spEditor.putString("orgName", orgName);
        spEditor.putInt("mtPhotoNo", mtPhotoNo);

        spEditor.commit();


        tvcompany.setText(orgName);
        userMember(orgId);
        behalfCharge(adId, ftId + "");
        initroleData(userMark, eeMark, adId, orgId, headMark, voMark);//角色
        popWindowApt = new PopWindowApt(getContext(), cusList, R.layout.popwindow_item_layout);

        if (popWindowApt.getCount() == 1) {
            img_home12.setVisibility(View.INVISIBLE);
        } else {
            img_home12.setVisibility(View.VISIBLE);
        }

    }

    private void initSecondCompany(LoginUserBean userInfo) {

        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        List<LoginUserBean.DataBean.CurUserOrgBean> curuserOrglist = data.getCur_userOrg();
        cusList.clear();
        if (curuserOrglist.size() == 0) {
            img_home12.setVisibility(View.INVISIBLE);

            return;
        }
        for (int i = 0; i < curuserOrglist.size(); i++) {
            if (curuserOrglist.get(i).getMark() == 1 || curuserOrglist.get(i).getMark() == 3 || curuserOrglist.get(i).getMark() == 4) {
                cusList.add(curuserOrglist.get(i));
            }
        }
        if (cusList.size() == 0) {
            img_home12.setVisibility(View.INVISIBLE);
            SharedPreferences sppp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor2 = sppp.edit();
            editor2.putInt("Mark", 2);
            editor2.putString("orgId", "");
            editor2.commit();
            tvcompany.setText("");
            return;
        }

        SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
        int orgIdlist = sp.getInt("orgIdlist", 0);
        String orgName = cusList.get(orgIdlist).getOrgName();
        String orgId = cusList.get(orgIdlist).getOrgId();
        int eeMark = cusList.get(orgIdlist).getEeMark();
        int mark = cusList.get(orgIdlist).getMark();
        int userMark = cusList.get(orgIdlist).getUserMark();
        adId = cusList.get(orgIdlist).getAdId();
        uoSn = cusList.get(orgIdlist).getUoSn();
        int orgMark = cusList.get(orgIdlist).getOrgMark();
        int minPer = cusList.get(orgIdlist).getMinPer();
        int signMark = cusList.get(orgIdlist).gettSignMark();
        int photoMark = cusList.get(orgIdlist).gettPhotoMark();
        int mtPhotoNo = cusList.get(orgIdlist).getMtPhotoNo();
        int readInterval = cusList.get(orgIdlist).getReadInterval();
        int pjtMinPer = cusList.get(orgIdlist).getPjtMinPer();
        String forbidHour = cusList.get(orgIdlist).getForbidHour();
        int headMark = cusList.get(orgIdlist).getHeadMark();
        int faceRecgMark = cusList.get(orgIdlist).getFaceRecgMark();
        String channelId = cusList.get(orgIdlist).getChannelId();
        int ihveMark = cusList.get(orgIdlist).getIhveMark();
        int voMark = cusList.get(orgIdlist).getVoMark();
        int mtPeriodMark = cusList.get(orgIdlist).getMtPeriodMark();
        int chNoMark = cusList.get(orgIdlist).getChNoMark();
        int mtSeqMark = cusList.get(orgIdlist).getMtSeqMark();
        int allowMuT = cusList.get(orgIdlist).getAllowMuT();
        int ftId = cusList.get(orgIdlist).getFtId();
        feeType = cusList.get(orgIdlist).getFeeType();
        ccMark = cusList.get(orgIdlist).getCcMark();
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("mtPhotoNo", mtPhotoNo);
        editor.putInt("Mark", mark);
        editor.putInt("eeMark", eeMark);
        editor.putString("orgId", orgId);
        editor.putString("orgName", orgName);
        editor.putString("forbidHour", forbidHour);
        editor.putInt("minPer", minPer);
        editor.putInt("pjtMinPer", pjtMinPer);
        editor.putInt("readInterval", readInterval);
        editor.putString("adId", adId);
        editor.putInt("userMark", userMark);
        editor.putInt("orgMark", orgMark);
        editor.putInt("signMark", signMark);
        editor.putInt("photoMark", photoMark);
        editor.putInt("headMark", headMark);
        editor.putInt("faceRecgMark", faceRecgMark);
        editor.putString("channelId", channelId);
        editor.putInt("ihveMark", ihveMark);
        editor.putInt("feeType", feeType);
        editor.putInt("voMark", voMark);
        editor.putInt("mtPeriodMark", mtPeriodMark);
        editor.putInt("chNoMark", chNoMark);
        editor.putInt("mtSeqMark", mtSeqMark);
        editor.putInt("allowMuT", allowMuT);
        editor.putInt("ftId", ftId);
        editor.commit();

        tvcompany.setText(orgName);
        userMember(orgId);
        behalfCharge(adId, ftId + "");
        initroleData(userMark, eeMark, adId, orgId, headMark, voMark);//角色
        popWindowApt = new PopWindowApt(getContext(), cusList, R.layout.popwindow_item_layout);
        if (popWindowApt.getCount() == 1) {
            img_home12.setVisibility(View.INVISIBLE);
        } else {
            img_home12.setVisibility(View.VISIBLE);
        }

    }

    //判断有通知没有
    private void initnoficationdata(String orgId) {

        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月");
        Date date = new Date(System.currentTimeMillis());
        String format1 = simpleDateFormat.format(date);
        String year1 = format1.substring(0, 5);
        String month1 = format1.substring(5);
        Calendar cal1 = Calendar.getInstance();
        cal1.set(Calendar.YEAR, Integer.parseInt(year1.substring(0, 4)));
        cal1.set(Calendar.MONTH, Integer.parseInt(month1.substring(0, 2)));
        cal1.set(Calendar.DAY_OF_MONTH, 1);
        cal1.add(Calendar.DAY_OF_MONTH, -1);
        Date lastDate1 = cal1.getTime();
        String endTime = new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(lastDate1);
        new Login().getNotice(3, orgId, userId, "2017-01-01 00:00:00", endTime, 1, 1000, this, 1);


    }


    private void initroleData(int userMark, int eeMark, String adId, String orgId, int headMark, int voMark) {
        SharedPreferences sP = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
        String orgId1 = sP.getString("orgId", "");
        if (orgId1.equals("")) {
            return;
        }
        LogUtils.e("测试", "initroleData: "+userMark+" "+eeMark+" "+headMark+" "+voMark );
        fgt_management.setText("安全管理");
        if (userMark == 1)//我是单位人员
        {
            roleList.clear();
            roleList.add(new RoleNameBean("我是单位人员"));
            String name = roleList.get(0).getName();
            tv_role.setText(name);
            SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sp1.edit();
            edit.putString("name" + orgId, name);
            edit.putInt("userMark", userMark);
            edit.putInt("eeMark", eeMark);
            edit.commit();
            appModule(adId, userMark, eeMark, name);
            popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);

            if (popWindowRoleApt.getCount() == 1) {
                img_role.setVisibility(View.INVISIBLE);
            } else {
                img_role.setVisibility(View.VISIBLE);
            }

        } else if (userMark == 2 && eeMark == 0)//我是企业管理人员
        {
            if (headMark == 0) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp1.edit();
                    edit.putString("name" + orgId, name);
                    edit.putInt("userMark", userMark);
                    edit.putInt("eeMark", eeMark);
                    edit.commit();
                    appModule(adId, userMark, eeMark, name);
                    tv_role.setText(name);
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, eeMark, name);
                        tv_role.setText(name);
                    } else if (rolename.equals(name)) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.commit();
                        appModule(adId, 2, eeMark, rolename);
                        tv_role.setText(name);
                    } else {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", 3);
                        edit.commit();
                        appModule(adId, 2, 3, rolename);
                        tv_role.setText("我是车主");
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }
            } else if (headMark == 1) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, eeMark, name);
                        tv_role.setText(name);
                    } else if (rolename.equals(name)) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.commit();
                        appModule(adId, 2, eeMark, rolename);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals("我是企业负责人")) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", eeMark);
                            edit.commit();
                            appModule(adId, 2, eeMark, rolename);
                            tv_role.setText("我是企业负责人");
                        } else {
                            if (name.equals("我是企业管理人员")) {
                                edit.putString("name" + orgId, name);
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", eeMark);
                                edit.commit();
                                appModule(adId, 2, eeMark, name);
                                tv_role.setText("我是企业负责人");
                            } else if (name.equals("我是企业负责人")) {
                                edit.putString("name" + orgId, name);
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", eeMark);
                                edit.commit();
                                appModule(adId, 2, eeMark, name);
                                tv_role.setText("我是企业负责人");

                            }
                        }
                    }
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, eeMark, name);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals(name)) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", eeMark);
                            edit.commit();
                            appModule(adId, 2, eeMark, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是企业负责人")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", eeMark);
                                edit.commit();
                                appModule(adId, 2, eeMark, rolename);
                                tv_role.setText("我是企业负责人");
                            } else if (rolename.equals("我是车主")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 3);
                                edit.commit();
                                appModule(adId, 2, 3, rolename);
                                tv_role.setText("我是车主");
                            }
                        }
                    }
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }

            }
        } else if (userMark == 3 && eeMark == 0)//我是企业管理人员
        {
            if (headMark == 0) {

                if (voMark == 0) {

                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp1.edit();
                    edit.putString("name" + orgId, name);
                    edit.putInt("userMark", 2);
                    edit.putInt("eeMark", eeMark);
                    edit.commit();
                    appModule(adId, 2, eeMark, name);
                    tv_role.setText(name);
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, eeMark, name);
                        tv_role.setText(name);
                    } else if (rolename.equals(name)) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.commit();
                        appModule(adId, 2, eeMark, rolename);
                        tv_role.setText(name);
                    } else {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", 3);
                        edit.commit();
                        appModule(adId, 2, 3, rolename);
                        tv_role.setText("我是车主");
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }
            } else if (headMark == 1) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, eeMark, name);
                        tv_role.setText(name);
                    } else if (rolename.equals(name)) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.commit();
                        appModule(adId, 2, eeMark, rolename);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals("我是企业负责人")) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", eeMark);
                            edit.commit();
                            appModule(adId, 2, eeMark, rolename);
                            tv_role.setText("我是企业负责人");
                        } else {
                            if (name.equals("我是企业管理人员")) {
                                edit.putString("name" + orgId, name);
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", eeMark);
                                edit.commit();
                                appModule(adId, 2, eeMark, name);
                                tv_role.setText(name);
                            } else if (name.equals("我是企业负责人")) {
                                edit.putString("name" + orgId, name);
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", eeMark);
                                edit.commit();
                                appModule(adId, 2, eeMark, name);
                                tv_role.setText("我是企业负责人");
                            }
                        }
                    }
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, eeMark, name);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals(name)) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", eeMark);
                            edit.commit();
                            appModule(adId, 2, eeMark, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是企业负责人")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", eeMark);
                                edit.commit();
                                appModule(adId, 2, eeMark, rolename);
                                tv_role.setText("我是企业负责人");
                            } else if (rolename.equals("我是车主")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 3);
                                edit.commit();
                                appModule(adId, 2, 3, rolename);
                                tv_role.setText("我是车主");
                            }
                        }
                    }
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }
            }
        } else if (userMark == 2 && eeMark == 1)//我是企业管理人员和从业人员
        {
            if (headMark == 0) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", userMark);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, userMark, 0, name);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals(name)) {
                            edit.putInt("userMark", userMark);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, userMark, 0, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, userMark, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else {
                                if (name.equals("我是企业管理人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", userMark);
                                    edit.putInt("eeMark", 0);
                                    edit.commit();
                                    appModule(adId, userMark, 0, name);
                                    tv_role.setText(name);
                                } else if (name.equals("我是从业人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", userMark);
                                    edit.putInt("eeMark", 1);
                                    edit.commit();
                                    appModule(adId, userMark, 1, name);
                                    tv_role.setText("我是从业人员");
                                    fgt_management.setText("安全作业");
                                }
                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", userMark);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, userMark, 0, name);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals(name)) {
                            edit.putInt("userMark", userMark);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, userMark, 0, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, userMark, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else if (rolename.equals("我是车主")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 3);
                                edit.commit();
                                appModule(adId, userMark, 3, rolename);
                                tv_role.setText("我是车主");
                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }

            } else if (headMark == 1) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", userMark);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, userMark, 0, name);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals(name)) {
                            edit.putInt("userMark", userMark);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, userMark, 0, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, userMark, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else if (rolename.equals("我是企业负责人")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 0);
                                edit.commit();
                                appModule(adId, userMark, 0, rolename);
                                tv_role.setText("我是企业负责人");

                            } else {
                                if (name.equals("我是企业管理人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 0);
                                    edit.commit();
                                    appModule(adId, 2, 0, name);
                                    tv_role.setText(name);
                                } else if (name.equals("我是从业人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 1);
                                    edit.commit();
                                    appModule(adId, 2, 1, name);
                                    tv_role.setText("我是从业人员");
                                    fgt_management.setText("安全作业");
                                } else if (name.equals("我是企业负责人")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 0);
                                    edit.commit();
                                    appModule(adId, 2, 0, name);
                                    tv_role.setText("我是企业负责人");

                                }

                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", userMark);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, userMark, 0, name);
                        tv_role.setText(name);
                    } else {
                        if (rolename.equals(name)) {
                            edit.putInt("userMark", userMark);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, userMark, 0, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, userMark, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else if (rolename.equals("我是企业负责人")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 0);
                                edit.commit();
                                appModule(adId, userMark, 0, rolename);
                                tv_role.setText("我是企业负责人");

                            } else if (rolename.equals("我是车主")) {
                                edit.putInt("userMark", userMark);
                                edit.putInt("eeMark", 3);
                                edit.commit();
                                appModule(adId, userMark, 3, rolename);
                                tv_role.setText("我是车主");
                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }
            }
        } else if (userMark == 3 && eeMark == 1)//我是企业管理人员和从业人员
        {
            if (headMark == 0) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, 0, name);

                        tv_role.setText(name);
                    } else {

                        if (rolename.equals(name)) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, 2, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else {
                                if (name.equals("我是企业管理人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 0);
                                    edit.commit();
                                    appModule(adId, 2, 0, name);
                                    tv_role.setText("我是企业管理人员");
                                } else if (name.equals("我是从业人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 1);
                                    edit.commit();
                                    appModule(adId, 2, 1, name);
                                    tv_role.setText("我是从业人员");
                                    fgt_management.setText("安全作业");
                                }
                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, 0, name);

                        tv_role.setText(name);
                    } else {

                        if (rolename.equals(name)) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, rolename);
                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, 2, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else if (rolename.equals("我是车主")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 3);
                                edit.commit();
                                appModule(adId, 2, 3, rolename);
                                tv_role.setText("我是车主");
                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }
            } else if (headMark == 1) {
                if (voMark == 0) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, 0, name);

                        tv_role.setText(name);
                    } else {

                        if (rolename.equals(name)) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, rolename);

                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, 2, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else if (rolename.equals("我是企业负责人")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 0);
                                edit.commit();
                                appModule(adId, 2, 0, rolename);
                                tv_role.setText("我是企业负责人");

                            } else {
                                if (name.equals("我是企业管理人员")) {
                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 0);
                                    edit.commit();
                                    appModule(adId, 2, 0, name);
                                    tv_role.setText(name);
                                } else if (name.equals("我是从业人员")) {

                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 1);
                                    edit.commit();
                                    appModule(adId, 2, 1, name);
                                    tv_role.setText("我是从业人员");
                                    fgt_management.setText("安全作业");
                                } else if (name.equals("我是企业负责人")) {

                                    edit.putString("name" + orgId, name);
                                    edit.putInt("userMark", 2);
                                    edit.putInt("eeMark", 0);
                                    edit.commit();
                                    appModule(adId, 2, 0, name);
                                    tv_role.setText("我是企业负责人");

                                }

                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                } else if (voMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是企业管理人员"));
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是企业负责人"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", 2);
                        edit.putInt("eeMark", 0);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, 2, 0, name);

                        tv_role.setText(name);
                    } else {

                        if (rolename.equals(name)) {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 0);
                            edit.commit();
                            appModule(adId, 2, 0, rolename);

                            tv_role.setText(name);
                        } else {
                            if (rolename.equals("我是从业人员")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 1);
                                edit.commit();
                                appModule(adId, 2, 1, rolename);
                                tv_role.setText("我是从业人员");
                                fgt_management.setText("安全作业");
                            } else if (rolename.equals("我是企业负责人")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 0);
                                edit.commit();
                                appModule(adId, 2, 0, rolename);
                                tv_role.setText("我是企业负责人");

                            } else if (rolename.equals("我是车主")) {
                                edit.putInt("userMark", 2);
                                edit.putInt("eeMark", 3);
                                edit.commit();
                                appModule(adId, 2, 3, rolename);
                                tv_role.setText("我是车主");

                            }
                        }
                    }

                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }

            }
        } else if (userMark == 0)//我是从业人员
        {
            if (voMark == 0) {
                if (eeMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是从业人员"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp1.edit();
                    edit.putString("name" + orgId, name);
                    edit.putInt("userMark", userMark);
                    edit.putInt("eeMark", eeMark);
                    edit.commit();
                    appModule(adId, userMark, eeMark, name);
                    tv_role.setText(name);
                    fgt_management.setText("安全作业");
                    popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);

                    if (popWindowRoleApt.getCount() == 1) {
                        img_role.setVisibility(View.INVISIBLE);
                    } else {
                        img_role.setVisibility(View.VISIBLE);
                    }
                }
            } else if (voMark == 1) {
                if (eeMark == 1) {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是从业人员"));
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    String rolename = sp.getString("name" + orgId, "");
                    SharedPreferences.Editor edit = sp.edit();
                    if (rolename.equals("")) {
                        edit.putInt("userMark", userMark);
                        edit.putInt("eeMark", eeMark);
                        edit.putString("name" + orgId, name);
                        edit.commit();
                        appModule(adId, userMark, eeMark, name);
                        tv_role.setText(name);
                    } else {

                        if (rolename.equals(name)) {
                            edit.putInt("userMark", userMark);
                            edit.putInt("eeMark", eeMark);
                            edit.commit();
                            appModule(adId, userMark, eeMark, rolename);
                            fgt_management.setText("安全作业");
                            tv_role.setText(name);
                        } else {
                            edit.putInt("userMark", 2);
                            edit.putInt("eeMark", 3);
                            edit.commit();
                            appModule(adId, 2, 3, rolename);
                            tv_role.setText("我是车主");

                        }
                    }
                } else {
                    roleList.clear();
                    roleList.add(new RoleNameBean("我是车主"));
                    String name = roleList.get(0).getName();
                    SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp1.edit();
                    edit.putString("name" + orgId, name);
                    edit.putInt("userMark", userMark);
                    edit.putInt("eeMark", eeMark);
                    edit.commit();
                    appModule(adId, userMark, eeMark, name);
                    tv_role.setText(name);
                }
                popWindowRoleApt = new PopWindowRoleApt(getContext(), roleList, R.layout.popwindow_item_layout);
                if (popWindowRoleApt.getCount() == 1) {
                    img_role.setVisibility(View.INVISIBLE);
                } else {
                    img_role.setVisibility(View.VISIBLE);
                }
            }
        }
    }


    @Override
    public void onResume() {
        super.onResume();

        //刷新一下专项学习购买情况
        SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
        String adId = sp.getString("adId", "");
        String orgId = sp.getString("orgId", "");
        SharedPreferences sp1 = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
        int userMark = sp1.getInt("userMark", 0);
        int eeMark = sp1.getInt("eeMark", 0);
        String Name = sp1.getString("name" + orgId, "");
        if (orgId.equals("")) {
            return;
        }

        appModule(adId, userMark, eeMark, Name);
    }


    private void showPopupWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.popwindow_layout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        ListView lv_company = (ListView) contentView.findViewById(R.id.lv_company);
        lv_company.setAdapter(popWindowApt);
//       mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
        mPopWindow.showAtLocation(tvcompany, Gravity.CENTER, 0, 0);
//        mPopWindow.showAsDropDown(tvcompany);
        lv_company.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                if (popWindowApt != null) {
                    String orgName = popWindowApt.getItem(position).getOrgName();
                    String orgId = popWindowApt.getItem(position).getOrgId();
                    int eeMark = popWindowApt.getItem(position).getEeMark();
                    int mark = popWindowApt.getItem(position).getMark();
                    adId = popWindowApt.getItem(position).getAdId();
                    uoSn = popWindowApt.getItem(position).getUoSn();
                    int userMark = popWindowApt.getItem(position).getUserMark();
                    int orgMark = popWindowApt.getItem(position).getOrgMark();
                    int minPer = popWindowApt.getItem(position).getMinPer();
                    int signMark = popWindowApt.getItem(position).gettSignMark();
                    int photoMark = popWindowApt.getItem(position).gettPhotoMark();
                    int mtPhotoNo = popWindowApt.getItem(position).getMtPhotoNo();
                    int pjtMinPer = popWindowApt.getItem(position).getPjtMinPer();
                    String forbidHour = popWindowApt.getItem(position).getForbidHour();
                    int headMark = popWindowApt.getItem(position).getHeadMark();
                    int faceRecgMark = popWindowApt.getItem(position).getFaceRecgMark();
                    //   int satMark = popWindowApt.getItem(position).getSatMark();
                    int ihveMark = popWindowApt.getItem(position).getIhveMark();
                    int voMark = popWindowApt.getItem(position).getVoMark();
                    int mtPeriodMark = popWindowApt.getItem(position).getMtPeriodMark();
                    int chNoMark = popWindowApt.getItem(position).getChNoMark();
                    int mtSeqMark = popWindowApt.getItem(position).getMtSeqMark();
                    int allowMuT = popWindowApt.getItem(position).getAllowMuT();
                    String channelId = popWindowApt.getItem(position).getChannelId();
                    int ftId = popWindowApt.getItem(position).getFtId();
                    feeType = popWindowApt.getItem(position).getFeeType();
                    ccMark = popWindowApt.getItem(position).getCcMark();

                    SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putInt("eeMark", eeMark);
                    editor.putString("orgId", orgId);
                    editor.putString("orgName", orgName);
                    editor.putInt("minPer", minPer);
                    editor.putInt("pjtMinPer", pjtMinPer);
                    editor.putInt("Mark", mark);
                    editor.putString("adId", adId);
                    editor.putInt("mtPhotoNo", mtPhotoNo);
                    editor.putString("forbidHour", forbidHour);
                    editor.putInt("userMark", userMark);
                    editor.putInt("orgMark", orgMark);
                    editor.putInt("signMark", signMark);
                    editor.putInt("photoMark", photoMark);
                    editor.putInt("orgIdlist", position);
                    editor.putInt("headMark", headMark);
                    editor.putInt("faceRecgMark", faceRecgMark);
                    editor.putString("channelId", channelId);
                    editor.putInt("ihveMark", ihveMark);
                    editor.putInt("feeType", feeType);
                    editor.putInt("voMark", voMark);
                    editor.putInt("mtPeriodMark", mtPeriodMark);
                    editor.putInt("chNoMark", chNoMark);
                    editor.putInt("mtSeqMark", mtSeqMark);
                    editor.putInt("allowMuT", allowMuT);
                    editor.putInt("ftId", ftId);
                    editor.commit();

                    String photoUrl = sp.getString("personphotoUrl", "");

                    SharedPreferences sharedPreferences = getActivity().getSharedPreferences("StaticData", Context.MODE_PRIVATE);
                    SharedPreferences.Editor spEditor = sharedPreferences.edit();
                    spEditor.putString("adId", adId);
                    spEditor.putInt("uoSn", uoSn);
                    spEditor.putString("orgId", orgId);
                    spEditor.putInt("faceRecgMark", faceRecgMark);
                    spEditor.putString("personphotoUrl", photoUrl);
                    spEditor.putString("orgName", orgName);
                    spEditor.putInt("mtPhotoNo", mtPhotoNo);
                    spEditor.commit();

                    getConnectPhone(orgId);

                    mPopWindow.dismiss();
                    tvcompany.setText(orgName);
                    userMember(orgId);
                    behalfCharge(adId, ftId + "");
                    initroleData(userMark, eeMark, adId, orgId, headMark, voMark);//角色
                }
            }
        });
    }

    //根据企业或者行政规划获取动态模块
    private void appModule(String adId, int userMark, int eeMark, String name) {

        SharedPreferences sp = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString("rolename", name);
        edit.commit();
        new Login().getAppModule(adId, userMark, eeMark, this, 4);
    }

    //第一次进入界面获取当前用户机构信息
    private void useData() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        userId = data.getUserId();
        userName = data.getUserName();

        new Login().getUseData(userId, 1, this, 6);
        new Login().getUser(userId, this, 1);
    }

    //刷新获取当前用户机构信息
    private void ptruseData() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();

        new Login().getUseData(userId, 1, this, 8);

    }


    @Override
    public void requestData() {

        //  BannerData(); //广告数据接口刷新
        useData();//从新获取当前用户机构信息
        //  SignInData();//签到展示
        useDatapop();//弹窗企业
        usephoto(); //个人用户信息查询拍照
        usefacephoto(); //人脸识别要求上传头像和签名
        judgeData();//判断万胜企业是否进去

        new Login().getstrationDivision("510000", HomeFgt.this, 13);//查询指定行政区划信息及其下级
    }

    private void judgeData() {

        OkGo.get(AppInterfaceConfig.BASE_URL + "wx/specTWhiteOrg")
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        OrgIdBean orgIdBean = JSON.parseObject(s, OrgIdBean.class);
                        List<OrgIdBean.RowsBean> rows = orgIdBean.getRows();
                        orgidlist.clear();
                        orgidlist.addAll(rows);
                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);

                    }
                });
    }

    private void usefacephoto() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        new Login().getUser(userId, this, 12);
    }


    private void usephoto() {

        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        new Login().getUser(userId, this, 9);
    }

    private void useDatapop() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();

        new Login().getUseData(userId, 1, this, 7);

    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        super.onSuccess(result, call, response, what);
        if (what == 1) {
            MineUseBean mineUseBean = JSON.parseObject(result, MineUseBean.class);
            MineUseBean.DataBean data = mineUseBean.getData();
            idcNo = data.getIdcNo();
            nation = data.getNation();
            address = data.getAddress();
            userName = data.getUserName();
        } else if (what == 2) {
            if(stIdFlag==0){

            }else if(stIdFlag==1){
                startActivity(ThematiclearningActivity.class, certListBundle);
            }
        } else if (what == 4) {
            SharedPreferences sp1 = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
            String orgId = sp1.getString("orgId", "");
            int mark = sp1.getInt("Mark", 0);
            int feeType = sp1.getInt("feeType", 0);
            SharedPreferences sp = getActivity().getSharedPreferences("role", Context.MODE_PRIVATE);
            String rolename = sp.getString("name" + orgId, "");
            if (rolename.equals("我是车主")) {
                tv_homelearn2.setVisibility(View.VISIBLE);
                learn_gv.setAdapter(null);
                le_parent_check.setVisibility(View.GONE);

            } else {
                if (mark == 1) {
                    //其他角色正常显示
                    tv_homelearn2.setVisibility(View.GONE);
                    AppModule appModule = JSON.parseObject(result, AppModule.class);
                    List<AppModule.RowsBean> rows = appModule.getRows();
                    moduleTypeOneList.clear();
                    moduleTypeTwoList.clear();
                    for (int i = 0; i < rows.size(); i++) {
                        if (rows.get(i).getModuleType() == 1) {
                            moduleTypeOneList.add(rows.get(i));
                        } else if (rows.get(i).getModuleType() == 2) {
                            moduleTypeTwoList.add(rows.get(i));
                        }
                    }
                    if (moduleTypeOneList.size() == 0) {
                        le_parent_learn.setVisibility(View.GONE);
                    } else {
                        le_parent_learn.setVisibility(View.VISIBLE);
                        ArrayList<AppModule.RowsBean> OneList1 = new ArrayList<>();
                        OneList1.clear();
                        speList.clear();
                        for (int j = 0; j < moduleTypeOneList.size(); j++) {
                            if (moduleTypeOneList.get(j).getModuleId() != 20100011) {
                                OneList1.add(moduleTypeOneList.get(j));
                            } else if (moduleTypeOneList.get(j).getModuleId() == 20100011) {
                                speList.add(moduleTypeOneList.get(j));
                            }

                        }

                        maintAdapter = new MaintAdapter(getActivity(), OneList1, R.layout.main_gridview_item);

                        learn_gv.setAdapter(maintAdapter);

                        if (speList.size() == 1) {
                            SharedPreferences sp2 = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                            String orgId1 = sp2.getString("orgId", "");
                            String adId = sp2.getString("adId", "");
                            String name = sp2.getString("rolename", "");
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            LoginUserBean.DataBean data = userInfo.getData();
                            String userId = data.getUserId();

                            if (name.equals("我是从业人员") || name.equals("我是车主")) {
                                new Login().getRolespecifiedlearn(adId, orgId1, userId, 1 + "", "", "", this, 10);//驾驶员专项学习
                            } else if (name.equals("我是企业负责人")) {
                                new Login().getRolespecifiedlearn(adId, orgId1, userId, "", 1 + "", "", this, 10);//负责人专项学习
                            } else if (name.equals("我是企业管理人员") || name.equals("我是单位人员")) {
                                new Login().getRolespecifiedlearn(adId, orgId1, userId, "", "", 1 + "", this, 10);//安全员专项学习
                            }

                        } else {
                            re_specifiedlearn.setVisibility(View.GONE);
                        }


                    }
                    if (moduleTypeTwoList.size() == 0) {
                        le_parent_check.setVisibility(View.GONE);
                    } else {
                        le_parent_check.setVisibility(View.VISIBLE);
                        maintAdapter1 = new MaintSecondAdapter(getActivity(), moduleTypeTwoList, R.layout.main_gridview_item);
                        maintenance_gv.setAdapter(maintAdapter1);

                    }
                } else if (mark == 3) {
                    if (feeType == 2) {
                        //正常显示
                        tv_homelearn2.setVisibility(View.GONE);
                        AppModule appModule = JSON.parseObject(result, AppModule.class);
                        List<AppModule.RowsBean> rows = appModule.getRows();
                        moduleTypeOneList.clear();
                        moduleTypeTwoList.clear();
                        for (int i = 0; i < rows.size(); i++) {
                            if (rows.get(i).getModuleType() == 1) {
                                moduleTypeOneList.add(rows.get(i));
                            } else if (rows.get(i).getModuleType() == 2) {
                                moduleTypeTwoList.add(rows.get(i));
                            }
                        }
                        if (moduleTypeOneList.size() == 0) {
                            le_parent_learn.setVisibility(View.GONE);
                        } else {
                            le_parent_learn.setVisibility(View.VISIBLE);
                            ArrayList<AppModule.RowsBean> OneList1 = new ArrayList<>();
                            OneList1.clear();
                            speList.clear();
                            for (int j = 0; j < moduleTypeOneList.size(); j++) {
                                if (moduleTypeOneList.get(j).getModuleId() != 20100011) {
                                    OneList1.add(moduleTypeOneList.get(j));
                                } else if (moduleTypeOneList.get(j).getModuleId() == 20100011) {
                                    speList.add(moduleTypeOneList.get(j));
                                }

                            }

                            maintAdapter = new MaintAdapter(getActivity(), OneList1, R.layout.main_gridview_item);

                            learn_gv.setAdapter(maintAdapter);
                            if (speList.size() == 1) {
                                SharedPreferences sp2 = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                                String orgId1 = sp2.getString("orgId", "");
                                String adId = sp2.getString("adId", "");
                                String name = sp2.getString("rolename", "");
                                LoginUserBean userInfo = UserManger.getUserInfo();
                                LoginUserBean.DataBean data = userInfo.getData();
                                String userId = data.getUserId();

                                if (name.equals("我是从业人员") || name.equals("我是车主")) {
                                    new Login().getRolespecifiedlearn(adId, orgId1, userId, 1 + "", "", "", this, 10);//驾驶员专项学习
                                } else if (name.equals("我是企业负责人")) {
                                    new Login().getRolespecifiedlearn(adId, orgId1, userId, "", 1 + "", "", this, 10);//负责人专项学习
                                } else if (name.equals("我是企业管理人员") || name.equals("我是单位人员")) {
                                    new Login().getRolespecifiedlearn(adId, orgId1, userId, "", "", 1 + "", this, 10);//安全员专项学习
                                }

                            } else {
                                re_specifiedlearn.setVisibility(View.GONE);
                            }

                        }
                        if (moduleTypeTwoList.size() == 0) {
                            le_parent_check.setVisibility(View.GONE);
                        } else {
                            le_parent_check.setVisibility(View.VISIBLE);
                            maintAdapter1 = new MaintSecondAdapter(getActivity(), moduleTypeTwoList, R.layout.main_gridview_item);
                            maintenance_gv.setAdapter(maintAdapter1);

                        }
                    } else if (feeType == 1) {//只能用专项培训
                        //正常显示
                        tv_homelearn2.setVisibility(View.GONE);
                        AppModule appModule = JSON.parseObject(result, AppModule.class);
                        List<AppModule.RowsBean> rows = appModule.getRows();
                        moduleTypeOneList.clear();
                        moduleTypeTwoList.clear();
                        for (int i = 0; i < rows.size(); i++) {
                            if (rows.get(i).getModuleType() == 1) {
                                moduleTypeOneList.add(rows.get(i));
                            } else if (rows.get(i).getModuleType() == 2) {
                                moduleTypeTwoList.add(rows.get(i));
                            }
                        }
                        if (moduleTypeOneList.size() == 0) {
                            le_parent_learn.setVisibility(View.GONE);
                        } else {
                            le_parent_learn.setVisibility(View.VISIBLE);
                            ArrayList<AppModule.RowsBean> OneList1 = new ArrayList<>();
                            OneList1.clear();
                            speList.clear();
                            for (int j = 0; j < moduleTypeOneList.size(); j++) {
                                if (moduleTypeOneList.get(j).getModuleId() != 20100011) {
                                    OneList1.add(moduleTypeOneList.get(j));
                                } else if (moduleTypeOneList.get(j).getModuleId() == 20100011) {
                                    speList.add(moduleTypeOneList.get(j));
                                }

                            }

                            maintAdapter = new MaintAdapter(getActivity(), OneList1, R.layout.main_gridview_item);

                            learn_gv.setAdapter(maintAdapter);
                            if (speList.size() == 1) {
                                SharedPreferences sp2 = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                                String orgId1 = sp2.getString("orgId", "");
                                String adId = sp2.getString("adId", "");
                                String name = sp2.getString("rolename", "");
                                LoginUserBean userInfo = UserManger.getUserInfo();
                                LoginUserBean.DataBean data = userInfo.getData();
                                String userId = data.getUserId();

                                if (name.equals("我是从业人员") || name.equals("我是车主")) {
                                    new Login().getRolespecifiedlearn(adId, orgId1, userId, 1 + "", "", "", this, 10);//驾驶员专项学习
                                } else if (name.equals("我是企业负责人")) {
                                    new Login().getRolespecifiedlearn(adId, orgId1, userId, "", 1 + "", "", this, 10);//负责人专项学习
                                } else if (name.equals("我是企业管理人员") || name.equals("我是单位人员")) {
                                    new Login().getRolespecifiedlearn(adId, orgId1, userId, "", "", 1 + "", this, 10);//安全员专项学习
                                }

                            } else {
                                re_specifiedlearn.setVisibility(View.GONE);
                            }

                        }
                        if (moduleTypeTwoList.size() == 0) {
                            le_parent_check.setVisibility(View.GONE);
                        } else {
                            le_parent_check.setVisibility(View.VISIBLE);
                            maintAdapter1 = new MaintSecondAdapter(getActivity(), moduleTypeTwoList, R.layout.main_gridview_item);
                            maintenance_gv.setAdapter(maintAdapter1);

                        }
                    }
                } else if (mark == 4) {//只能用专项培训
                    //正常显示
                    tv_homelearn2.setVisibility(View.GONE);
                    tv_homelearn2.setVisibility(View.GONE);
                    AppModule appModule = JSON.parseObject(result, AppModule.class);
                    List<AppModule.RowsBean> rows = appModule.getRows();
                    moduleTypeOneList.clear();
                    moduleTypeTwoList.clear();
                    for (int i = 0; i < rows.size(); i++) {
                        if (rows.get(i).getModuleType() == 1) {
                            moduleTypeOneList.add(rows.get(i));
                        } else if (rows.get(i).getModuleType() == 2) {
                            moduleTypeTwoList.add(rows.get(i));
                        }
                    }
                    if (moduleTypeOneList.size() == 0) {
                        le_parent_learn.setVisibility(View.GONE);
                    } else {
                        le_parent_learn.setVisibility(View.VISIBLE);
                        ArrayList<AppModule.RowsBean> OneList1 = new ArrayList<>();
                        OneList1.clear();
                        speList.clear();
                        for (int j = 0; j < moduleTypeOneList.size(); j++) {
                            if (moduleTypeOneList.get(j).getModuleId() != 20100011) {
                                OneList1.add(moduleTypeOneList.get(j));
                            } else if (moduleTypeOneList.get(j).getModuleId() == 20100011) {
                                speList.add(moduleTypeOneList.get(j));
                            }

                        }

                        maintAdapter = new MaintAdapter(getActivity(), OneList1, R.layout.main_gridview_item);

                        learn_gv.setAdapter(maintAdapter);
                        if (speList.size() == 1) {
                            SharedPreferences sp2 = getActivity().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                            String orgId1 = sp2.getString("orgId", "");
                            String adId = sp2.getString("adId", "");
                            String name = sp2.getString("rolename", "");
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            LoginUserBean.DataBean data = userInfo.getData();
                            String userId = data.getUserId();

                            if (name.equals("我是从业人员") || name.equals("我是车主")) {
                                new Login().getRolespecifiedlearn(adId, orgId1, userId, 1 + "", "", "", this, 10);//驾驶员专项学习
                            } else if (name.equals("我是企业负责人")) {
                                new Login().getRolespecifiedlearn(adId, orgId1, userId, "", 1 + "", "", this, 10);//负责人专项学习
                            } else if (name.equals("我是企业管理人员") || name.equals("我是单位人员")) {
                                new Login().getRolespecifiedlearn(adId, orgId1, userId, "", "", 1 + "", this, 10);//安全员专项学习
                            }

                        } else {
                            re_specifiedlearn.setVisibility(View.GONE);
                        }

                    }
                    if (moduleTypeTwoList.size() == 0) {
                        le_parent_check.setVisibility(View.GONE);
                    } else {
                        le_parent_check.setVisibility(View.VISIBLE);
                        maintAdapter1 = new MaintSecondAdapter(getActivity(), moduleTypeTwoList, R.layout.main_gridview_item);
                        maintenance_gv.setAdapter(maintAdapter1);
                    }
                }

            }

        } else if (what == 6) {//第一次进入获取用户信息
            UserBean userBean = JSON.parseObject(result, UserBean.class);
            List<LoginUserBean.DataBean.CurUserOrgBean> rows = userBean.getRows();
            useList.clear();
            useList.addAll(rows);
            LoginUserBean userInfo = UserManger.getUserInfo();
            userInfo.getData().setCur_userOrg(useList);
            UserManger.setUserInfo(userInfo);
            initCompany(userInfo);

            // EventBus.getDefault().post(new MessageEvent(userInfo));
        } else if (what == 7) {//弹窗企业
            UserBean userBean = JSON.parseObject(result, UserBean.class);
            List<LoginUserBean.DataBean.CurUserOrgBean> rows = userBean.getRows();

            if (rows.size() == 0) {
                return;
            }
            cusList1.clear();
            for (int i = 0; i < rows.size(); i++) {
                if (rows.get(i).getMark() == 1 || rows.get(i).getMark() == 3 || rows.get(i).getMark() == 4) {
                    cusList1.add(rows.get(i));
                }
            }
            if (cusList1.size() == 0) {
                return;
            }
            popWindowApt = new PopWindowApt(getContext(), cusList1, R.layout.popwindow_item_layout);

            if (popWindowApt.getCount() > 1) {
                showPopupWindow();
            }


        } else if (what == 8) {//刷新更新一下用户信息
            UserBean userBean = JSON.parseObject(result, UserBean.class);
            List<LoginUserBean.DataBean.CurUserOrgBean> rows = userBean.getRows();

            useList.clear();
            useList.addAll(rows);
            LoginUserBean userInfo = UserManger.getUserInfo();
            userInfo.getData().setCur_userOrg(useList);
            UserManger.setUserInfo(userInfo);
            initSecondCompany(userInfo);
            // EventBus.getDefault().post(new MessageEvent(userInfo));
        } else if (what == 9) {
            MineUseBean mineUseBean = JSON.parseObject(result, MineUseBean.class);
            MineUseBean.DataBean data = mineUseBean.getData();
            String photoUrl = data.getPhotoUrl();

            LoginUserBean userInfo1 = UserManger.getUserInfo();
            LoginUserBean.DataBean databean = userInfo1.getData();
            if (databean == null) {
                return;
            }
            String lastLoginDate = databean.getLastLoginDate();
            if (lastLoginDate == null)//返回空值时弹窗
            {
                if (photoUrl == null) {

                    showTakePhotoPopupWindow();
                }
            }
        } else if (what == 10) {
            SpecifiedLearnAllBean specifiedLearnAllBean = JSON.parseObject(result, SpecifiedLearnAllBean.class);
            List<SpecifiedLearnAllBean.RowsBean> rows = specifiedLearnAllBean.getRows();
            speciledList.clear();
            cashList.clear();
            if (rows.size() == 0) {
                re_specifiedlearn.setVisibility(View.GONE);
                return;
            }
            re_specifiedlearn.setVisibility(View.VISIBLE);

            for (int i = 0; i < rows.size(); i++) {
                if (rows.get(i).getShowTrml() != 3) {
                    cashList.add(rows.get(i));
                }
            }

            if (cashList.size() == 1) {
                speciledList.add(cashList.get(0));
            } else if (cashList.size() == 2) {
                speciledList.add(cashList.get(0));
                speciledList.add(cashList.get(1));
            } else if (cashList.size() >= 3) {
                speciledList.add(cashList.get(0));
                speciledList.add(cashList.get(1));
                speciledList.add(cashList.get(2));
            }
            specifiedLearnGVAdapter = new SpecifiedLearnGVAdapter(getContext(), speciledList, R.layout.alltopics_home_item_layout);
            specified_gv.setAdapter(specifiedLearnGVAdapter);

        } else if (what == 11) {
            SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
            String orgId = sp.getString("orgId", "");
            String orgName = sp.getString("orgName", "");
            int stId = sp.getInt("stId", 0);
            int ihveMark = sp.getInt("ihveMark", 0);
            int tmenuMark = sp.getInt("tmenuMark", 0);
            int qmenuMark = sp.getInt("qmenuMark", 0);
            int peMenuMark = sp.getInt("peMenuMark", 0);
            int emenuMark = sp.getInt("emenuMark", 0);
            int position = sp.getInt("position", 0);
            String adId = sp.getString("adId", "");
            String rolename = sp.getString("rolename", "");
            String iconUrl = sp.getString("iconUrl", "");
            int seqTMark = sp.getInt("seqTMark", 0);
            Bundle bundle = new Bundle();
            bundle.putString("orgId", orgId);
            bundle.putInt("stId", stId);
            bundle.putString("orgName", orgName);
            bundle.putString("adId", adId);
            bundle.putString("rolename", rolename);
            bundle.putString("iconUrl", iconUrl);
            bundle.putInt("position", position);
            bundle.putInt("ihveMark", ihveMark);
            bundle.putInt("tmenuMark", tmenuMark);
            bundle.putInt("qmenuMark", qmenuMark);
            bundle.putInt("peMenuMark", peMenuMark);
            bundle.putInt("emenuMark", emenuMark);
            bundle.putInt("seqTMark", seqTMark);
            bundle.putInt("reapplyMark",reapplyMark);
            startActivity(ThematiclearningActivity.class, bundle);
        } else if (what == 12) {
            MineUseBean mineUseBean = JSON.parseObject(result, MineUseBean.class);
            MineUseBean.DataBean data = mineUseBean.getData();
            String photoUrl = data.getPhotoUrl();
            if (photoUrl == null) {
                SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("personphotoUrl", "");
                edit.commit();
            } else {
                SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("personphotoUrl", photoUrl);
                edit.commit();
            }
            String signUrl = data.getSignUrl();
            if (signUrl == null) {
                SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("signUrl", "");
                edit.commit();
            } else {
                SharedPreferences sp = getContext().getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("signUrl", signUrl);
                edit.commit();
            }

        } else if (what == 13) {
            StrationCityBean strationCityBean = JSON.parseObject(result, StrationCityBean.class);
            StrationCityBean.DataBean data = strationCityBean.getData();
            List<StrationCityBean.DataBean.NextListBean> nextList = data.getNextList();
            citys = new String[nextList.size() + 1];
            citys[0] = "选择市";
            for (int i = 0; i < nextList.size(); i++) {
                citys[i + 1] = nextList.get(i).getNextAdName();
            }
        } else if (what == CHECK_IS_BUY_MEMBER) {
            UserVipCheckBean bean = JSON.parseObject(result, UserVipCheckBean.class);
            checkResult = bean.isResult();
        } else if (what == CHECK_BEHALF_CHARGE) {

            TrainingIndvPriceCheckBean bean = JSON.parseObject(result, TrainingIndvPriceCheckBean.class);
            int data = bean.getData();
            if (data > 0) {
                behalfCharge = true;
            } else {
                behalfCharge = false;
            }
        }
    }


    @Override
    public void onError(String result, Call call, Response response, int what) {
        super.onError(result, call, response, what);
        if (what == 11) {
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            String msg = checkBean.getMsg();
            HelpUtil.showTiShiDialog(getContext(), msg);
        } else if (what == CHECK_IS_BUY_MEMBER) {
            UserVipCheckBean bean = JSON.parseObject(result, UserVipCheckBean.class);
            checkResult = bean.isResult();
        } else if (what == CHECK_BEHALF_CHARGE) {
            LogUtils.e("测试111", "onError: " + result);
        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return false;
    }

    public class MaintAdapter extends CommonAdapter<AppModule.RowsBean> {
        private final List<AppModule.RowsBean> mList;
        private Context context;
        // 标记用户当前选择
        private int index = -1;

        public MaintAdapter(Context context, List<AppModule.RowsBean> mList, int itemLayoutId) {
            super(context, mList, itemLayoutId);
            this.context = context;
            this.mList = mList;
        }

        @Override
        public void convert(com.android.frame.adapter.ViewHolder holder, AppModule.RowsBean item, final int position) {


            ImageView img_gv = holder.getView(R.id.img_main);
            TextView tv_main = holder.getView(R.id.tv_main);

            String url = mList.get(position).getIconUrl();
            String moduleName = mList.get(position).getModuleName();
            tv_main.setText(moduleName);
            if (url != null) {
                Picasso.with(mContext).load(Uri.parse(url)).placeholder(R.mipmap.nophoto).into(img_gv);
            }
        }
    }

    public class SpecifiedLearnGVAdapter extends CommonAdapter<SpecifiedLearnAllBean.RowsBean> {
        private final List<SpecifiedLearnAllBean.RowsBean> mList;
        private Context context;
        // 标记用户当前选择
        private int index = -1;

        public SpecifiedLearnGVAdapter(Context context, List<SpecifiedLearnAllBean.RowsBean> mList, int itemLayoutId) {
            super(context, mList, itemLayoutId);
            this.context = context;
            this.mList = mList;

        }

        @Override
        public void convert(com.android.frame.adapter.ViewHolder holder, SpecifiedLearnAllBean.RowsBean item, final int position) {

            ImageView img_alltop = holder.getView(R.id.img_alltop);
            TextView tv_name = holder.getView(R.id.tv_name);
            TextView tv_inside = holder.getView(R.id.tv_inside);
            String iconUrl = mList.get(position).getIconUrl();
            SharedPreferences sp = context.getSharedPreferences("homefgt", Context.MODE_PRIVATE);
            String rolename = sp.getString("rolename", "");
            if (rolename.equals("我是从业人员")) {
                tv_name.setText("驾驶员");
            } else if (rolename.equals("我是企业负责人")) {
                tv_name.setText("负责人");
            } else if (rolename.equals("我是企业管理人员") || rolename.equals("我是单位人员")) {
                tv_name.setText("安全员");
            } else if (rolename.equals("我是车主")) {
                tv_name.setText("车主");
            }
            if (iconUrl != null) {
                Picasso.with(mContext).load(Uri.parse(iconUrl)).placeholder(R.mipmap.no_data2).into(img_alltop);
            }

            Integer uschSn = mList.get(position).getUschSn();
            Integer chargeMark = mList.get(position).getChargeMark();
            Integer payMark = mList.get(position).getPayMark();
            if (uschSn == null) {
                if (chargeMark == 1) {
                    tv_inside.setText("进入");
                    tv_inside.setTextColor(getActivity().getResources().getColor(R.color.project_blue));
                } else if (chargeMark == 2 || chargeMark == 3) {
                    tv_inside.setText("未参加");
                    tv_inside.setTextColor(getActivity().getResources().getColor(R.color.project_redsecond));
                }

            } else {
                if (chargeMark == 1) {
                    tv_inside.setText("进入");
                    tv_inside.setTextColor(getActivity().getResources().getColor(R.color.project_blue));
                } else if (chargeMark == 3) {
                    tv_inside.setText("进入");
                    tv_inside.setTextColor(getActivity().getResources().getColor(R.color.project_blue));
                } else if (chargeMark == 2) {
                    if (payMark == 2) {
                        tv_inside.setText("进入");
                        tv_inside.setTextColor(getActivity().getResources().getColor(R.color.project_blue));
                    } else {
                        tv_inside.setText("进入");
                        tv_inside.setTextColor(getActivity().getResources().getColor(R.color.project_blue));
                    }

                }
            }

        }


    }


    //获取手机的唯一标识
    @SuppressLint("MissingPermission")
    public String getPhoneSign() {
        StringBuilder deviceId = new StringBuilder();
        // 渠道标志
        deviceId.append("a");
        try {
            // IMEI（imei）
            TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
            String imei = tm.getDeviceId();
            if (!TextUtils.isEmpty(imei)) {
                deviceId.append("imei");
                deviceId.append(imei);
                return deviceId.toString();
            }
            //序列号（sn）
            String sn = tm.getSimSerialNumber();
            if (!TextUtils.isEmpty(sn)) {
                deviceId.append("sn");
                deviceId.append(sn);
                return deviceId.toString();
            }
            //如果上面都没有， 则生成一个id：随机码
            String uuid = getUUID();
            if (!TextUtils.isEmpty(uuid)) {
                deviceId.append("id");
                deviceId.append(uuid);
                return deviceId.toString();
            }
        } catch (Exception e) {
            e.printStackTrace();
            deviceId.append("id").append(getUUID());
        }
        return deviceId.toString();
    }

    //得到全局唯一UUID
    private String uuid;

    public String getUUID() {
        SharedPreferences mShare = getActivity().getSharedPreferences("uuid", Context.MODE_PRIVATE);
        if (mShare != null) {
            uuid = mShare.getString("uuid", "");
        }
        if (TextUtils.isEmpty(uuid)) {
            uuid = UUID.randomUUID().toString();
            mShare.edit().putString("uuid", uuid).commit();
        }
        return uuid;
    }

    public boolean IsIDcard(String str) {
        String regex = "(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}[0-9Xx]$)";
        return match(regex, str);
    }

    private boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

    //企业状态
    private boolean orgStatus(int orgMark, String orgName) {
        boolean orgStatusUseAble = false;
        if (orgMark == 0) {
            HelpUtil.showTiShiDialog(getActivity(), "您所在的企业" + orgName + "是无效状态，请联系管理员或者平台管理员（" + contactPhone + "）");
        } else if (orgMark == 2) {
            HelpUtil.showTiShiDialog(getActivity(), "您所在的企业" + orgName + "是待审核状态，请联系管理员或者平台管理员（" + contactPhone + "）");
        } else if (orgMark == 3) {
            HelpUtil.showTiShiDialog(getActivity(), "您所在的企业" + orgName + "还未审核通过，请联系管理员或者平台管理员（" + contactPhone + "）");
        } else if (orgMark == 4) {
            HelpUtil.showTiShiDialog(getActivity(), "您" + orgName + "企业“余额”或者“学时”不足，请联系企业管理员或者平台管理员（" + contactPhone + "）");
        } else {
            orgStatusUseAble = true;
        }
        return orgStatusUseAble;
    }


    //会员校验
    private void userMember(String orgId) {
        new Login().userVipCheck(userId, orgId, "", this, CHECK_IS_BUY_MEMBER);  //用户是否在会员期内
    }

    //校验是否开启代收费
    private void behalfCharge(String adId, String ftId) {
        new Login().trainingIndvPriceCheck(adId, ftId, this, CHECK_BEHALF_CHARGE);
    }

    //是否购买包年会员判断
    private boolean buyMemberCheck() {
        boolean result = false;
        if (tv_role.getText().toString().trim().equals("我是从业人员")) {  //从业人员
            if (feeType == 2) { //个人付费
                if (!checkResult) { //不在会员期内
                    if (behalfCharge) { //是否有会员体系
                        result = true;
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getContext());
                        builder1.setMessage("您所属企业需购买会员");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                        builder1.setNegativeButton("取消",
                                new android.content.DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                    }
                                });
                        builder1.create().show();
                        /*if(ccMark==1){
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getContext());
                            builder1.setMessage("您所属企业需购买会员");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    startActivity(BehalfChargeActivity.class, null);
                                }
                            });
                            builder1.setNegativeButton("取消",
                                    new android.content.DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                        }
                                    });
                            builder1.create().show();
                        }else if(ccMark==0){
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getContext());
                            builder1.setMessage("您所属企业需购买会员");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    startActivity(MemberInfoActivity.class, null);
                                }
                            });
                            builder1.setNegativeButton("取消",
                                    new android.content.DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                        }
                                    });

                            builder1.create().show();
                        }*/
                    }
                }
            }
        }
        return result;
    }

    //永川交通判断
    private boolean isYCJT(String adId) {
        boolean result = false;
        if (adId.equals("500118")) {
            result = true;

            View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_hint, null);
            mPopWindow = new PopupWindow(contentView,
                    WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
            //设置各个控件的点击响应
            mPopWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);
            ImageView dgHintIv = contentView.findViewById(R.id.dg_hint_iv);
            ImageView dgHintIvClose = contentView.findViewById(R.id.dg_hint_iv_close);
            TextView mobile1 = contentView.findViewById(R.id.dg_hint_tv_mobile1);
            TextView mobile2 = contentView.findViewById(R.id.dg_hint_tv_mobile2);

            mobile1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    Uri data = Uri.parse("tel:18996175288");
                    intent.setData(data);
                    startActivity(intent);
                }
            });
            mobile2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    Uri data = Uri.parse("tel:02386058530");
                    intent.setData(data);
                    startActivity(intent);
                }
            });

            dgHintIvClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mPopWindow.dismiss();
                }
            });

            BitmapDrawable bg = (BitmapDrawable) dgHintIv.getDrawable();
            Bitmap bitmap = bg.getBitmap();
            dgHintIv.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    FileUtil.saveImageToGallery(getContext(), bitmap);
                    showToast("保存相册成功");
                    return false;
                }
            });
        }
        return result;
    }

    //网络请求
    private void getConnectPhone(String orgId) { //获取联系电话
        OkGo.get(AppInterfaceConfig.BASE_URL + "sys/config/findContact/" + orgId)
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String result, Call call, Response response) {
                        ContactBean bean = JSON.parseObject(result, ContactBean.class);
                        if (bean.getData().getContactPhone() != null) {
                            contactPhone = bean.getData().getContactPhone();
                        }
                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);

                    }
                });
    }
}
